2017-02-18 20:21:34 +01:00
|
|
|
'use strict';
|
|
|
|
|
2020-11-18 23:10:43 +01:00
|
|
|
const express = require('express');
|
|
|
|
const bodyParser = require('body-parser');
|
|
|
|
const expect = require('chai').expect;
|
|
|
|
const cors = require('cors');
|
|
|
|
require('dotenv').config();
|
2017-02-18 20:21:34 +01:00
|
|
|
|
2020-11-18 23:10:43 +01:00
|
|
|
const apiRoutes = require('./routes/api.js');
|
|
|
|
const fccTestingRoutes = require('./routes/fcctesting.js');
|
|
|
|
const runner = require('./test-runner');
|
2017-02-18 20:21:34 +01:00
|
|
|
|
2020-11-18 23:10:43 +01:00
|
|
|
let app = express();
|
2017-02-18 20:21:34 +01:00
|
|
|
|
|
|
|
app.use('/public', express.static(process.cwd() + '/public'));
|
|
|
|
|
|
|
|
app.use(cors({origin: '*'})); //For FCC testing purposes only
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.use(bodyParser.json());
|
|
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
|
|
|
|
|
|
//Sample front-end
|
|
|
|
app.route('/:project/')
|
|
|
|
.get(function (req, res) {
|
|
|
|
res.sendFile(process.cwd() + '/views/issue.html');
|
|
|
|
});
|
|
|
|
|
|
|
|
//Index page (static HTML)
|
|
|
|
app.route('/')
|
|
|
|
.get(function (req, res) {
|
|
|
|
res.sendFile(process.cwd() + '/views/index.html');
|
|
|
|
});
|
|
|
|
|
|
|
|
//For FCC testing purposes
|
|
|
|
fccTestingRoutes(app);
|
|
|
|
|
|
|
|
//Routing for API
|
|
|
|
apiRoutes(app);
|
|
|
|
|
|
|
|
//404 Not Found Middleware
|
|
|
|
app.use(function(req, res, next) {
|
|
|
|
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('Running Tests...');
|
|
|
|
setTimeout(function () {
|
|
|
|
try {
|
|
|
|
runner.run();
|
|
|
|
} catch(e) {
|
2020-11-18 23:10:43 +01:00
|
|
|
let error = e;
|
2017-02-18 20:21:34 +01:00
|
|
|
console.log('Tests are not valid:');
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
}, 3500);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = app; //for testing
|