From 4655fcc74df78d919a5628d86aeead0639e01283 Mon Sep 17 00:00:00 2001 From: Kar Date: Mon, 18 Dec 2023 16:50:07 +0530 Subject: [PATCH] init --- .env.sample | 4 ++++ .gitignore | 5 +++++ LICENSE | 12 +++++++++++ README.md | 2 ++ id_rsa.pub.sample | 1 + id_rsa.sample | 9 ++++++++ index.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++ origin.cors.sample | 3 +++ package.json | 15 +++++++++++++ 9 files changed, 104 insertions(+) create mode 100644 .env.sample create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 id_rsa.pub.sample create mode 100644 id_rsa.sample create mode 100644 index.js create mode 100644 origin.cors.sample create mode 100644 package.json diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..f672e85 --- /dev/null +++ b/.env.sample @@ -0,0 +1,4 @@ +PORT = 8012 +JWT_SECRET_KEY = 866406d1-5649-48d1-8ad6-2db11f8c739d +TOKEN_HEADER_KEY = 7ccdhSsaXL3SfHkCeKmEr5LAlrSLNRTe + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f50d9e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules +.env +id_rsa +id_rsa.pub +origin.cors diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..729447b --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +MUKTI +license Mukti/Moksh - 'the liberation' is a basic realization that the result of distribution or giving away does not always come short rather increases step by step, specially when things are non physical. MUKTI is not a license but a step towards a license free civilization. +Human race is better with 'some sense' rather a bunch of license. [have some sense, not licenses.] + +till all the licenses are deprecated and decentralize [ specially for software, hardware, education, experience,even the network protocol (internet) ], lets use freedom centric and/or having "take if it helps you, just don't sue us - kind of mentality" licenses like GPL, MIT, BSD ... + +this will not be registered / certified / legalise in any manner, as it's not about enforcement - it is about freedom to share. + +example of 'some sense': + verbose incremental documentation with versioning, attaching contributor information. + try to make some OFFERING to the contributor or the contributing organization with or without a subscription / support. + maximize the use of freedom centric tools[hardware, software, os ...] enen if it costs and costs more, try not to be the product. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d2f28ba --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +#saveToMongo +## save api data to mongodb diff --git a/id_rsa.pub.sample b/id_rsa.pub.sample new file mode 100644 index 0000000..3598323 --- /dev/null +++ b/id_rsa.pub.sample @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDANAsOHd40dbUz+FGLYChyzOme7LmdD+CJQutjEjLSbqi9r/fcHxfFVFIwFKESGUxaPmu+qemmHGyT6cq8mLmx0iN28Odn3RpHe3AEc0SDyp55e7nBfoU0Ze7s6AZ2PacJEAn3pW5EMixu8RwZ0tRi2rnHL46AwwBMhlZ2HR4zM+zNcNQBs1qFS46H5vHN6VEKtRiiS8Srg7hh/MMl+blK7kgHVseVh6XQ6TitUEFFDbzhWfCviZXYxlTgmpDFL+bLP95Pjcic10P5PkAlFW0w5rf6YXv2pbsgpC30R72oASDkAOZoqiRRfswdNDimkIDf9xny6sw4e0KiLbFi24/l jwtKey diff --git a/id_rsa.sample b/id_rsa.sample new file mode 100644 index 0000000..d83cc85 --- /dev/null +++ b/id_rsa.sample @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwDQLDh3eNHW1M/hRi2Ao +cszpnuy5nQ/giULrYxIy0m6ova/33B8XxVRSMBShEhlMWj5rvqnpphxsk+nKvJi5 +sdIjdvDnZ90aR3twBHNEg8qeV3u55X6FNGXu7OgGdj2nCRAJ96VuRDIsbvEcGdLU +Ytq5xy+OgMMATIZWdh0eMzPszXDUAbNahUuOh+bxzelRCrUYokvEq4O4YfzDJfm5 +Su5IB1bHlYel0Ok4rVBBRQ284Vnwr4mV2MZU4JqQxS/myz/eT43InNdD+T5AJRVt +MOa3+mF79qW7IKQt9Ee9qAEg5ADmaKokUX7MHTQ4ppCA3/cZ8urMOHtCoi2xYtuP +5QIDAQAB +-----END PUBLIC KEY----- diff --git a/index.js b/index.js new file mode 100644 index 0000000..a350117 --- /dev/null +++ b/index.js @@ -0,0 +1,53 @@ +const express = require('express'); +const dotenv = require('dotenv'); +// const jwt = require('jsonwebtoken'); +// const fs = require('fs'); +const cors = require('cors'); +const app = express(); +let corsOptions = fs.readFileSync('origin.cors'); +app.use(cors(corsOptions)); +dotenv.config(); +let port = process.env.PORT || 5000; + +mongoose.connect("mongodb://localhost:27017/mydb", { useNewUrlParser: true, useUnifiedTopology: true }); + +const PostSchema = new mongoose.Schema({ + title: String, + body: String, +}); + +const Post = mongoose.model("Post", PostSchema); + +app.get("/posts", async (req, res) => { + const posts = await Post.find(); + res.json(posts); +}); + +app.post("/posts", async (req, res) => { + const post = new Post({ + title: req.body.title, + body: req.body.body, + }); + + await post.save(); + + res.json(post); +}); + +app.put("/posts/:id", async (req, res) => { + const post = await Post.findByIdAndUpdate(req.params.id, req.body); + + res.json(post); +}); + +app.delete("/posts/:id", async (req, res) => { + await Post.findByIdAndRemove(req.params.id); + + res.json({ message: "Post deleted successfully" }); +}); + + +app.listen(port, () => { +console.log(`FileAccessJWT API listening on port ${port}`) +}) + diff --git a/origin.cors.sample b/origin.cors.sample new file mode 100644 index 0000000..9d8fc4e --- /dev/null +++ b/origin.cors.sample @@ -0,0 +1,3 @@ +{ + origin : ['https://cw.domain.in','https://cw.domain2.in','https://akademy.domain3.tech'], +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..04d4786 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "file-access-jwt", + "version": "1.0.0", + "private": true, + "scripts": { + "start": "node index.js", + "dev": "nodemon index.js" + }, + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^16.0.3", + "express": "^4.16.4", + "jsonwebtoken": "^9.0.0" + } +}