master
Kar 2023-12-18 16:50:07 +05:30
commit 4655fcc74d
9 changed files with 104 additions and 0 deletions

4
.env.sample Normal file
View File

@ -0,0 +1,4 @@
PORT = 8012
JWT_SECRET_KEY = 866406d1-5649-48d1-8ad6-2db11f8c739d
TOKEN_HEADER_KEY = 7ccdhSsaXL3SfHkCeKmEr5LAlrSLNRTe

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
node_modules
.env
id_rsa
id_rsa.pub
origin.cors

12
LICENSE Normal file
View File

@ -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.

2
README.md Normal file
View File

@ -0,0 +1,2 @@
#saveToMongo
## save api data to mongodb

1
id_rsa.pub.sample Normal file
View File

@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDANAsOHd40dbUz+FGLYChyzOme7LmdD+CJQutjEjLSbqi9r/fcHxfFVFIwFKESGUxaPmu+qemmHGyT6cq8mLmx0iN28Odn3RpHe3AEc0SDyp55e7nBfoU0Ze7s6AZ2PacJEAn3pW5EMixu8RwZ0tRi2rnHL46AwwBMhlZ2HR4zM+zNcNQBs1qFS46H5vHN6VEKtRiiS8Srg7hh/MMl+blK7kgHVseVh6XQ6TitUEFFDbzhWfCviZXYxlTgmpDFL+bLP95Pjcic10P5PkAlFW0w5rf6YXv2pbsgpC30R72oASDkAOZoqiRRfswdNDimkIDf9xny6sw4e0KiLbFi24/l jwtKey

9
id_rsa.sample Normal file
View File

@ -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-----

53
index.js Normal file
View File

@ -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}`)
})

3
origin.cors.sample Normal file
View File

@ -0,0 +1,3 @@
{
origin : ['https://cw.domain.in','https://cw.domain2.in','https://akademy.domain3.tech'],
}

15
package.json Normal file
View File

@ -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"
}
}