parent
8b4cba3314
commit
69adfdabc0
7
.env
7
.env
|
@ -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_PORT=6950
|
||||||
SERVER_HOST=0.0.0.0
|
|
||||||
|
# If development mode should be ON or OFF
|
||||||
|
DEV_MODE=TRUE
|
File diff suppressed because it is too large
Load Diff
|
@ -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",
|
||||||
|
|
12
src/app.ts
12
src/app.ts
|
@ -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 router = express();
|
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) => {
|
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}`)
|
||||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue