parent
8b4cba3314
commit
69adfdabc0
7
.env
7
.env
|
@ -1,2 +1,7 @@
|
|||
SERVER_PORT=6950
|
||||
# The ip address the server should listen on
|
||||
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
|
File diff suppressed because it is too large
Load Diff
|
@ -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",
|
||||
|
|
10
src/app.ts
10
src/app.ts
|
@ -8,20 +8,24 @@
|
|||
|
||||
//#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();
|
||||
|
||||
|
||||
// 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}`)
|
||||
|
|
|
@ -16,7 +16,8 @@ const SERVER = {
|
|||
|
||||
// The whole configuration
|
||||
const config = {
|
||||
server: SERVER
|
||||
server: SERVER,
|
||||
devmode: process.env.DEV_MODE || 0,
|
||||
};
|
||||
|
||||
export default config;
|
Loading…
Reference in New Issue