Skip to content

Commit

Permalink
feat: Live check on personal library (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
a2937 authored Nov 21, 2023
1 parent 05e2ccb commit 255cd7a
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions apps/personal-library/server.js
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down

0 comments on commit 255cd7a

Please sign in to comment.