From 255cd7ac811bd89f21cf637a49b057182e189ece Mon Sep 17 00:00:00 2001 From: a2937 Date: Tue, 21 Nov 2023 18:55:13 -0500 Subject: [PATCH] feat: Live check on personal library (#532) --- apps/personal-library/server.js | 47 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/apps/personal-library/server.js b/apps/personal-library/server.js index 1974a854..0d9bece3 100644 --- a/apps/personal-library/server.js +++ b/apps/personal-library/server.js @@ -1,54 +1,55 @@ 'use strict'; -const express = require('express'); -const bodyParser = require('body-parser'); -const cors = require('cors'); +const express = require('express'); +const bodyParser = require('body-parser'); +const cors = require('cors'); require('dotenv').config(); -const apiRoutes = require('./routes/api.js'); -const fccTestingRoutes = require('./routes/fcctesting.js'); -const runner = require('./test-runner'); +const apiRoutes = require('./routes/api.js'); +const fccTestingRoutes = require('./routes/fcctesting.js'); +const runner = require('./test-runner'); const app = express(); app.use('/public', express.static(process.cwd() + '/public')); -app.use(cors({origin: '*'})); //USED FOR FCC TESTING PURPOSES ONLY! +app.use(cors({ origin: '*' })); //USED FOR FCC TESTING PURPOSES ONLY! app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); //Index page (static HTML) -app.route('/') - .get(function (req, res) { - res.sendFile(process.cwd() + '/views/index.html'); - }); +app.route('/').get(function (req, res) { + res.sendFile(process.cwd() + '/views/index.html'); +}); + +app.get('/status/ping', (req, res) => { + res.status(200).send({ msg: 'pong' }); +}); //For FCC testing purposes fccTestingRoutes(app); -//Routing for API -apiRoutes(app); - +//Routing for API +apiRoutes(app); + //404 Not Found Middleware -app.use(function(req, res) { - res.status(404) - .type('text') - .send('Not Found'); +app.use(function (req, res) { + res.status(404).type('text').send('Not Found'); }); //Start our server and tests! app.listen(process.env.PORT || 3000, function () { - console.log("Listening on port " + process.env.PORT); - if(process.env.NODE_ENV==='test') { + console.log('Listening on port ' + process.env.PORT); + if (process.env.NODE_ENV === 'test') { console.log('Running Tests...'); setTimeout(function () { try { runner.run(); - } catch(e) { + } catch (e) { let error = e; - console.log('Tests are not valid:'); - console.log(error); + console.log('Tests are not valid:'); + console.log(error); } }, 1500); }