This repository has been archived on 2024-08-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
nubian/src/server.js

42 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-07-24 15:42:36 -06:00
//Imports
const express = require("express");
2021-07-24 23:05:27 -06:00
const cors = require("cors");
2021-07-24 15:42:36 -06:00
const bodyParser = require("body-parser");
const bearerToken = require("express-bearer-token");
2021-07-24 15:42:36 -06:00
//Local Imports
const { Web, StatusCode, Server } = require("./config.json");
//Import Routers
const stashRouter = require("./routes/stash");
//Define Constants & Setup Database
const app = express();
const port = Server.Port;
const debuggingMode = Server.Debug;
const viewOptions = { beautify: false };
2021-07-24 23:05:27 -06:00
const corsOptions = {
origin: "*",
optionsSuccessStatus: 200,
};
2021-07-24 15:42:36 -06:00
//Set Up Express session and View engine
2021-07-24 23:05:27 -06:00
app.use(cors(corsOptions));
app.use(bearerToken());
2021-07-24 15:42:36 -06:00
app.use(bodyParser.json({ limit: Server.BodyLimit })); // parse application/json
app.use(bodyParser.urlencoded({ limit: Server.BodyLimit, extended: false })); // parse application/x-www-form-urlencoded
//Test if there is a
app.use("/api/stash", stashRouter);
const startServer = () => {
server = app.listen(port, () => {
console.log("Node version:" + process.versions.node);
console.log(`Duneserver listening on port ${port}!`);
});
server.timeout = 10 * 60 * 1000;
server.on("connection", (socket) => {
// 10 minutes timeout
socket.setTimeout(10 * 60 * 1000);
});
process.on("SIGINT", () => {
console.log("Recieved Shutdown Signal!");
process.exit();
});
};
startServer();