+ 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 @@
# The ip address the server should listen on
SERVER_HOST=0.0.0.0
# The port to bind the server to
SERVER_PORT=6950
SERVER_HOST=0.0.0.0
# 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": {
"build": "rm -rf dist/* && tsc",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "DEV_MODE=TRUE && nodemon ./src/app.ts"
},
"author": "",
"license": "ISC",

View File

@ -8,20 +8,24 @@
//#endregion
const NAMESPACE = `🦝`;
const router = express();
// 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();
// Setup the router to log all activity that is happening
router.use((req, res, next) => {
// Log the request to the server
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`, () => {
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();
})
// Parse the request
@ -30,6 +34,7 @@ router.use(express.json({strict: false}));
// API Rules
router.use((req, res, next) => {
// Set some basic headers
res.header(`Access-Control-Allow-Origin`, `*`);
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);
httpServer.listen(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
const config = {
server: SERVER
server: SERVER,
devmode: process.env.DEV_MODE || 0,
};
export default config;