From 2505ef619bbb6b3e63d133574748915b8abe0ea1 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 13 Nov 2023 21:02:20 -0500 Subject: [PATCH] Feat: Live check for exercise tracker --- apps/exercise-tracker/server.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/exercise-tracker/server.js b/apps/exercise-tracker/server.js index 457f70f2..02be041d 100644 --- a/apps/exercise-tracker/server.js +++ b/apps/exercise-tracker/server.js @@ -7,15 +7,21 @@ const mongoose = require('mongoose'); mongoose.set('useUnifiedTopology', true); mongoose.set('useCreateIndex', true); -mongoose.connect(process.env.DB_URI || 'mongodb://localhost/exercise-track', { useNewUrlParser: true }); +mongoose.connect(process.env.DB_URI || 'mongodb://localhost/exercise-track', { + useNewUrlParser: true +}); -app.use(express.urlencoded({'extended': false})); +app.use(express.urlencoded({ extended: false })); app.use(express.json()); app.use(cors()); -app.use(express.static('public')) +app.use(express.static('public')); app.get('/', (req, res) => { - res.sendFile(__dirname + '/views/index.html') + res.sendFile(__dirname + '/views/index.html'); +}); + +app.get('/status/ping', (req, res) => { + res.status(200).send({ msg: 'pong' }); }); const apiRouter = require('./routes/api'); @@ -23,12 +29,12 @@ app.use('/api', apiRouter); // Not found middleware app.use((req, res, next) => { - return next({status: 404, message: 'not found'}); -}) + return next({ status: 404, message: 'not found' }); +}); // Error Handling middleware app.use((err, req, res) => { - let errCode, errMessage + let errCode, errMessage; if (err.errors) { // Mongoose validation error @@ -41,8 +47,7 @@ app.use((err, req, res) => { errCode = err.status || 500; errMessage = err.message || 'Internal Server Error'; } - res.status(errCode).type('txt') - .send(errMessage); + res.status(errCode).type('txt').send(errMessage); }); const portNum = process.env.PORT || 3000;