-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extracts status routes to single file
- Loading branch information
Showing
5 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
require('dotenv').config(); | ||
const express = require('express'); | ||
const path = require('path'); | ||
const pjson = require('pjson'); | ||
const cookieParser = require("cookie-parser"); | ||
const helmet = require('helmet'); | ||
const app = express(); | ||
const logger = require('./middlewares/logger'); | ||
const { launchLog } = require("./utils/logger.js") | ||
const { statusRoute } = require('./routes/routes.js'); | ||
const PORT = process.env.PORT || 3000; | ||
|
||
app.use(express.json()) | ||
|
@@ -15,17 +15,7 @@ app.use(helmet({ | |
contentSecurityPolicy: false | ||
})); | ||
app.use(logger); | ||
|
||
app.get('/status', (req, res) => { | ||
res.json({ | ||
Status: 'OK', | ||
'Runtime-Mode': process.env.ENV == 'pro' ? 'Production' : 'Development', | ||
'Application-Version': pjson.version, | ||
'Application-Description': 'migtarx.com BLOG', | ||
'Application-Author': '[email protected]', | ||
'Application-Owner': 'Miguel Puerta', | ||
}); | ||
}); | ||
app.use('/status', statusRoute); | ||
|
||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const statusController = require('./status.controller'); | ||
|
||
module.exports = { | ||
statusController | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require('dotenv').config(); | ||
const pjson = require('pjson'); | ||
const execMode = process.env.ENV; | ||
|
||
module.exports = { | ||
getStatus, | ||
getStatusHeartBeat | ||
}; | ||
|
||
function getServerStatusData(isHeartBeat = false){ | ||
const statusInformation = { | ||
Status: 'OK', | ||
'Runtime-Mode': execMode == 'prod' ? 'Production' : 'Development', | ||
'Application-Description': 'migtarx.com BLOG', | ||
'Application-Author': '[email protected]', | ||
'Application-Owner': 'Miguel Puerta', | ||
} | ||
if (!isHeartBeat) { | ||
statusInformation['Application-Version'] = pjson.version; | ||
} | ||
return statusInformation; | ||
} | ||
|
||
function getStatus(req, res) { | ||
return res.json(getServerStatusData()); | ||
} | ||
|
||
function getStatusHeartBeat(req, res) { | ||
return res.json(getServerStatusData(true)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const statusRoute = require('./status.route.js'); | ||
|
||
module.exports = { | ||
statusRoute | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const express = require('express'); | ||
const statusRouter = express.Router(); | ||
const { statusController } = require('../controllers'); | ||
|
||
statusRouter.get('/', statusController.getStatus); | ||
|
||
statusRouter.get('/heartbeat', statusController.getStatusHeartBeat); | ||
|
||
module.exports = statusRouter; |