+ DevMode Variable

* Small Tweaks Overall
This commit is contained in:
Daniel Legt 2021-05-29 19:06:33 +03:00
parent 8b4cba3314
commit 69adfdabc0
5 changed files with 27 additions and 3173 deletions

7
.env
View File

@ -1,2 +1,7 @@
SERVER_PORT=6950 # The ip address the server should listen on
SERVER_HOST=0.0.0.0 SERVER_HOST=0.0.0.0
# The port to bind the server to
SERVER_PORT=6950
# If development mode should be ON or OFF
DEV_MODE=TRUE

3176
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
}, },
"scripts": { "scripts": {
"build": "rm -rf dist/* && tsc", "build": "rm -rf dist/* && tsc",
"test": "echo \"Error: no test specified\" && exit 1" "test": "DEV_MODE=TRUE && nodemon ./src/app.ts"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",

View File

@ -8,20 +8,24 @@
//#endregion //#endregion
const NAMESPACE = `🦝`; // Declare a NameSpace constant for each file so that it's easier to identify where debug messages are coming from
const NAMESPACE = `App`;
// Setup the expressJS instance
const router = express(); const router = express();
// Setup the router to log all activity that is happening
router.use((req, res, next) => { router.use((req, res, next) => {
// Log the request to the server // Log the request to the server
console.info(NAMESPACE, `METHOD: [${req.method}], URL: [${req.url}], IP: [${req.socket.remoteAddress}]`); console.info(NAMESPACE, `METHOD: [${req.method}], URL: [${req.url}], IP: [${req.socket.remoteAddress}]`);
// Whenever we finish the request, send out a message telling us what exactly has happened to it.
res.on(`finish`, () => { res.on(`finish`, () => {
console.info(NAMESPACE, `METHOD: [${req.method}], URL: [${req.url}], IP: [${req.socket.remoteAddress}], STATUS: ${res.statusCode}`); console.info(NAMESPACE, `METHOD: [${req.method}], URL: [${req.url}], IP: [${req.socket.remoteAddress}], STATUS: ${res.statusCode}`);
}) })
// Run the next function queued for this request
next(); next();
}) })
// Parse the request // Parse the request
@ -30,6 +34,7 @@ router.use(express.json({strict: false}));
// API Rules // API Rules
router.use((req, res, next) => { router.use((req, res, next) => {
// Set some basic headers
res.header(`Access-Control-Allow-Origin`, `*`); res.header(`Access-Control-Allow-Origin`, `*`);
res.header(`Access-Control-Allow-Headers`, `Origin, X-Request-With, Content-Type, Accept, Authorization`); res.header(`Access-Control-Allow-Headers`, `Origin, X-Request-With, Content-Type, Accept, Authorization`);
@ -56,6 +61,7 @@ router.use('/sample', sampleRoutes);
}); });
} }
// Finally actually start the server and run it
const httpServer = http.createServer(router); const httpServer = http.createServer(router);
httpServer.listen(config.server.port, () => { httpServer.listen(config.server.port, () => {
console.info(NAMESPACE, `Server Running on Port ${config.server.hostname}:${config.server.port}`) console.info(NAMESPACE, `Server Running on Port ${config.server.hostname}:${config.server.port}`)

View File

@ -16,7 +16,8 @@ const SERVER = {
// The whole configuration // The whole configuration
const config = { const config = {
server: SERVER server: SERVER,
devmode: process.env.DEV_MODE || 0,
}; };
export default config; export default config;