Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
updated misc functions to bring up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
gamer-1478 committed Nov 1, 2023
1 parent 18d64f3 commit 24daf86
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .test.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SERVER_AUTH_STRING =
SERVER_BACKEND_VM = :3000
DISCORD_CLIENT_ID =
DISCORD_CLIENT_SECRET =
DISCORD_REDIRECT_URI =
DISCORD_REDIRECT_URI =
DISCORD_REDIRECT_URI_LOGIN =
GMAIL_EMAIL =
GMAIL_PASSWORD =
Expand Down
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ app.use((req, res, next) => {
app.set('view engine', 'ejs');

//mongo
const MONGO_PASSWORD = process.env.MONGO_PASSWORD
const MONGO_USER = process.env.MONGO_USER
const MONGO_CLUSTER_URL = process.env.MONGO_CLUSTER_URL
const MONGO_DATABASE_NAME = process.env.MONGO_DATABASE_NAME
const db = `mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@${MONGO_CLUSTER_URL}/${MONGO_DATABASE_NAME}?retryWrites=true&w=majority`
const db = process.env.MONGO_URI;

//passportJs
if (process.env.NODE_ENV === 'production') {
Expand Down Expand Up @@ -92,13 +88,14 @@ app.use((err, req, res, next) => {
next(err)
})

function serverHealth() {
CheckServerHealth('http://' + process.env.SERVER_BACKEND_VM + '/language').then((res) => {
async function serverHealth() {
CheckServerHealth(process.env.SERVER_BACKEND_VM + '/language').then(async (res) => {
if (res.status !== 200) {
ReportCodeExec('Code Execution Service Has Crashed Please Check <@823237564130525184>')
ReportCodeExec('Code Execution Service Has Crashed Please Check')
}
})
}

serverHealth();
setInterval(() => {
serverHealth()
Expand Down
24 changes: 11 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"moment": "^2.29.4",
"mongoose": "^6.4.6",
"nodemailer": "^6.7.2",
"passport": "^0.6.0",
"passport": "^0.5.0",
"passport-discord": "^0.1.4",
"passport-local": "^1.0.0"
}
Expand Down
5 changes: 3 additions & 2 deletions routers/answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ answer_router.post('/run/:id', checkAuthenticated, async (req, res) => {
language: req.params.id
}).save().then(async (dock) => {
await Axios({
url: 'http://' + process.env.SERVER_BACKEND_VM + '/language/' + req.params.id,
url: process.env.SERVER_BACKEND_VM + '/language/' + req.params.id,
withCredentials: true,
method: 'POST',
headers: {
Expand Down Expand Up @@ -91,7 +91,7 @@ answer_router.post('/submit/:id', checkAuthenticated, async (req, res) => {
// Make API Call to Run Code and Return the output
return new Promise(async (resolve, reject) => {
await Axios({
url: 'http://' + process.env.SERVER_BACKEND_VM + '/language/' + req.params.id,
url: process.env.SERVER_BACKEND_VM + '/language/' + req.params.id,
withCredentials: true,
method: 'POST',
headers: {
Expand All @@ -111,6 +111,7 @@ answer_router.post('/submit/:id', checkAuthenticated, async (req, res) => {
output: data.data.data,
output_compare: testcase.output_compare,
}
console.log(data.data.data)
if (data.data.data.join('\n') === testcase.output_compare) {
newTestcase.passed = true;
}
Expand Down
22 changes: 1 addition & 21 deletions routers/bloat.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,9 @@ const bloat_router = express.Router();
bloat_router.use(express.static('public'));

//cors middleware
const whitelist = ['ts-prog1.herokuapp.com', 'localhost', 'netlify.app', 'techsyndicate.us'];
const corsOptions = {
origin: (origin, callback) => {
if (origin) {
var urlParsed = url.parse(origin, true)
var included = false;
for (i in whitelist) {
if (urlParsed.hostname.includes(whitelist[i])) {
included = true;
callback(null, true);
}
else if (i == whitelist.length - 1 && !included) {
console.log("not allowed", urlParsed.hostname);
callback(new Error("Not allowed by CORS ORIGIN: " + urlParsed.hostname))
}
}
}
else if (!origin) {
callback(null, true)
} else {
console.log(origin, "Not allowed by CORS ORIGIN policy")
callback(new Error("Not allowed by CORS ORIGIN: " + origin))
}
callback(null, true);
},
credentials: true
}
Expand Down
2 changes: 2 additions & 0 deletions utilities/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ async function ReportCodeExec(content) {
}

async function CheckServerHealth(url) {
console.log(url)
return await Axios({
url: url,
method: 'GET',
timeout: 5000
}).then((res) => {
return res;
}).catch((err) => {
console.log(err)
return { err: err, sucess: false, msg: 'Server is down' };
});
}
Expand Down

0 comments on commit 24daf86

Please sign in to comment.