This commit updates how the service handles startup
This commit is contained in:
parent
614886fcd7
commit
8888b5d1ad
161
server.js
161
server.js
@ -5,15 +5,9 @@ const ObjectId = require("mongodb").ObjectID;
|
|||||||
const CONNECTION_URL = "mongodb+srv://edgenetworknode:yUiWfJBYCGwdRayj@matchnethop.hgxv0xd.mongodb.net/?retryWrites=true&w=majority";
|
const CONNECTION_URL = "mongodb+srv://edgenetworknode:yUiWfJBYCGwdRayj@matchnethop.hgxv0xd.mongodb.net/?retryWrites=true&w=majority";
|
||||||
const DATABASE_NAME = "edgecomm";
|
const DATABASE_NAME = "edgecomm";
|
||||||
const COLLECTION_NAME = "nettranslate";
|
const COLLECTION_NAME = "nettranslate";
|
||||||
const sha256 = require('js-sha256');
|
|
||||||
var cors = require('cors');
|
var cors = require('cors');
|
||||||
const Collection = require("mongodb/lib/collection");
|
|
||||||
const Db = require("mongodb/lib/db");
|
|
||||||
const MongoClient = require("mongodb").MongoClient;
|
const MongoClient = require("mongodb").MongoClient;
|
||||||
const request = require('undici');
|
|
||||||
const axios = require('axios');
|
|
||||||
const requestIp = require('request-ip');
|
const requestIp = require('request-ip');
|
||||||
let requestEnable = false;
|
|
||||||
var app = Express();
|
var app = Express();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(BodyParser.json());
|
app.use(BodyParser.json());
|
||||||
@ -25,6 +19,7 @@ var corsOptions = {
|
|||||||
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
|
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
|
||||||
}
|
}
|
||||||
var database, collection;
|
var database, collection;
|
||||||
|
var requestEnable = false;
|
||||||
/**GET*/
|
/**GET*/
|
||||||
app.get("/", (request, response) => {
|
app.get("/", (request, response) => {
|
||||||
response.json({
|
response.json({
|
||||||
@ -41,78 +36,90 @@ app.get("/lobby/listall/", async (request, response) => {
|
|||||||
Field LBN[num] breaks down into Lobby Name [Number], this informs the client what the name is of the assosiated lobby
|
Field LBN[num] breaks down into Lobby Name [Number], this informs the client what the name is of the assosiated lobby
|
||||||
Field LBIP[num] breaks down into Lobby IP [Number], this informs the client what the IP is of the assosiated lobby
|
Field LBIP[num] breaks down into Lobby IP [Number], this informs the client what the IP is of the assosiated lobby
|
||||||
*/
|
*/
|
||||||
var o_id = new mongodb.ObjectID();
|
if (requestEnable) {
|
||||||
var ar;
|
var o_id = new mongodb.ObjectID();
|
||||||
auth.insertOne({
|
var ar;
|
||||||
_id : o_id,
|
auth.insertOne({
|
||||||
type: 1,
|
_id : o_id,
|
||||||
status: false
|
type: 1,
|
||||||
})
|
status: false
|
||||||
await auth.findOne({_id: o_id}, (err, res) => {
|
})
|
||||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
|
await auth.findOne({_id: o_id}, (err, res) => {
|
||||||
const dec = async i => (await delay(200), --i)
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||||
ar = res;
|
const dec = async i => (await delay(200), --i)
|
||||||
const verifyUser = async () => {
|
ar = res;
|
||||||
let responseEnabled = true;
|
const verifyUser = async () => {
|
||||||
let enableLookup = true;
|
let responseEnabled = true;
|
||||||
let i = 8;
|
let enableLookup = true;
|
||||||
let timeout = 7;
|
let i = 8;
|
||||||
while(i = await dec(i))
|
let timeout = 7;
|
||||||
try {
|
while(i = await dec(i))
|
||||||
if (enableLookup) {
|
try {
|
||||||
timeout = timeout - 1;
|
if (enableLookup) {
|
||||||
if (timeout > 0) {
|
timeout = timeout - 1;
|
||||||
await auth.findOne({_id: o_id}, (err, res) => {
|
if (timeout > 0) {
|
||||||
if (res.status) {
|
await auth.findOne({_id: o_id}, (err, res) => {
|
||||||
if (responseEnabled) {
|
if (res.status) {
|
||||||
timeout = 0;
|
if (responseEnabled) {
|
||||||
i = 1;
|
timeout = 0;
|
||||||
if (res.type == 2) {
|
i = 1;
|
||||||
responseEnabled = false;
|
if (res.type == 2) {
|
||||||
enableLookup = false;
|
responseEnabled = false;
|
||||||
response.status(200).json({
|
enableLookup = false;
|
||||||
LBN : res.lobbies,
|
response.status(200).json({
|
||||||
LBIP : res.ip,
|
Info: "Good",
|
||||||
LobbyCount : res.LobbyCount
|
LBN : res.lobbies,
|
||||||
});
|
LBIP : res.ip,
|
||||||
res = null;
|
LobbyCount : res.LobbyCount
|
||||||
} else {
|
});
|
||||||
responseEnabled = false;
|
res = null;
|
||||||
ar = null;
|
} else {
|
||||||
res = null;
|
responseEnabled = false;
|
||||||
response.status(403).json({
|
ar = null;
|
||||||
Info: "Forbidden",
|
res = null;
|
||||||
Message: "Something went wrong."
|
response.status(403).json({
|
||||||
});
|
Info: "Forbidden",
|
||||||
}
|
Message: "Something went wrong."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
} else {
|
||||||
} else {
|
if (responseEnabled) {
|
||||||
if (responseEnabled) {
|
response.status(403).json({
|
||||||
response.status(403).json({
|
Info: "Forbidden",
|
||||||
Info: "Forbidden",
|
Message: "Something went wrong..."
|
||||||
Message: "Something went wrong..."
|
});
|
||||||
});
|
responseEnabled = false;
|
||||||
responseEnabled = false;
|
ar = null;
|
||||||
ar = null;
|
res = null;
|
||||||
res = null;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (err) {
|
||||||
} catch (err) {
|
enableLookup = false;
|
||||||
enableLookup = false;
|
res = null;
|
||||||
res = null;
|
if (responseEnabled) {
|
||||||
if (responseEnabled) {
|
response.status(503).json({
|
||||||
response.sendStatus(500);
|
Info: "Forbidden",
|
||||||
}
|
Message: "Something went wrong..."
|
||||||
responseEnabled = false;
|
});
|
||||||
console.log(err);
|
}
|
||||||
timeout = 1;
|
responseEnabled = false;
|
||||||
}
|
console.log(err);
|
||||||
}
|
timeout = 1;
|
||||||
verifyUser();
|
}
|
||||||
});
|
}
|
||||||
|
verifyUser();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
response.status(503).json({
|
||||||
|
Info: "Forbidden",
|
||||||
|
Message: "The server is starting up, please retry again in a moment."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
app.get("/lobby/submit/", async (request, response) => {
|
app.get("/lobby/submit/", async (request, response) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user