Skip to content

Commit

Permalink
node upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
souravrax committed Nov 6, 2024
1 parent 32157da commit c9198ac
Show file tree
Hide file tree
Showing 5 changed files with 673 additions and 397 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PORT=
CLIENT_ID=
CLIENT_SECRET=
URL=
DB_URL=
29 changes: 20 additions & 9 deletions Routers/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const URL = process.env.URL;

const mapLanguageToCode = require("../res/mapLanguageToCode.json");

router.post("/", (req, res) => {
router.post("/", async (req, res) => {
const { code, language, input, cArgs } = req.body;
const program = {
script: code,
Expand All @@ -19,15 +19,26 @@ router.post("/", (req, res) => {
clientSecret: clientSecret,
};
console.log("Execute Called:", program);
axios
.post(URL, program)
.then((response) => {
console.log("Responding with:", response.data);
res.status(200).json(response.data);
try {

const response = await axios({
method: "post",
url: URL,
data: program,
headers: {
"Content-Type": "application/json",
},
timeout: 5000,
validateStatus: (status) => {
return status >= 200 && status < 300;
},
})
.catch((error) => {
res.status(400).sendStatus(error);
});
return res.status(200).json(response.data);

} catch (error) {
console.error(error);
return res.status(400).sendStatus(error);
}
});

module.exports = router;
6 changes: 2 additions & 4 deletions Routers/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ const DB_CONNECTION = process.env.DB_URL;

// Mongoose connection
mongoose.connect(DB_CONNECTION, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
ssl: true,
tls: true,
});
const db = mongoose.connection;
db.on("error", console.error.bind(console, "Connection error:"));
Expand Down
47 changes: 25 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
{
"name": "CodeEditorProject",
"version": "1.0.0",
"description": "Backend of the online code editor project",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.2",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"helmet": "^4.2.0",
"mongoose": "^5.10.13",
"morgan": "^1.10.0",
"ms": "^2.1.2",
"rotating-file-stream": "^2.1.3"
}
"name": "code-editor-backend",
"version": "1.0.1",
"description": "Backend of the online code editor",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.7.7",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.1",
"helmet": "^8.0.0",
"mongoose": "8.8.0",
"morgan": "^1.10.0",
"ms": "^2.1.3",
"rotating-file-stream": "^3.2.5"
},
"devDependencies": {
"nodemon": "^3.1.7"
}
}
Loading

0 comments on commit c9198ac

Please sign in to comment.