* feat: show open boilerplate prs on dashboard fix: rest of boilerplate server changes fix: more fix: other * fix: update lib functions * fix: retrofitted one-off scripts * feat: added rateLimit for requests * fix: reduce time * fix: put limiter inside each route * fix: make client show when rated limited * fix: removed unused probot from app * fix: renamed folders * fix: consolidate config.js and constants.js * chore: update octokit to latest version * fix: remove invalid file * fix: refactored update-db.js * feat: add fcc logo * fix: logo url * fix: remove Home link * fix: change link colors * fix: added rate limiter to landing page * fix: ran npm install in client to create package-lock.json * fix: correct typo in doc Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com> * fix: Replace favicon, Gitter => Discord Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> * fix: add extra linting guidance to package.json * Ignore contributor app Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> * fix: revert linting rules for client * fix: add skip_preflight_check=true for tests Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Kris Koishigawa <scissorsneedfoodtoo@gmail.com> Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
const express = require('express');
|
|
const mongoose = require('mongoose');
|
|
const path = require('path');
|
|
|
|
const app = express();
|
|
const config = require('../../lib/config');
|
|
const { pareto, pr, search, info, allRepos } = require('./routes');
|
|
const { reqLimiter } = require('./req-limiter');
|
|
|
|
// May need to uncomment the following to get rateLimit to work properly since we are using reverse-proxy
|
|
// app.set('trust proxy', 1);
|
|
|
|
app.use(express.static(path.join(__dirname, '../client/build')));
|
|
|
|
app.use((request, response, next) => {
|
|
response.header('Access-Control-Allow-Origin', '*');
|
|
response.header(
|
|
'Access-Control-Allow-Headers',
|
|
'Origin, X-Requested-With, Content-Type, Accept'
|
|
);
|
|
response.header('Access-Control-Allow-Methods', 'GET');
|
|
next();
|
|
});
|
|
|
|
const landingPage = path.join(__dirname, '../client/build/index.html');
|
|
app.get('/', reqLimiter, (req, res) => res.sendFile(landingPage));
|
|
|
|
app.use('/pr', pr);
|
|
app.use('/search', search);
|
|
app.use('/pareto', pareto);
|
|
app.use('/info', info);
|
|
app.use('/all-repos', allRepos);
|
|
|
|
// 404
|
|
app.use(function(req, res) {
|
|
const message = 'Route' + req.url + ' Not found.';
|
|
console.log(message);
|
|
return res.status(404).send({ message });
|
|
});
|
|
|
|
// 500 - Any server error
|
|
app.use(function(err, req, res) {
|
|
console.log('error: ' + err);
|
|
return res.status(500).send({ error: err });
|
|
});
|
|
|
|
if (mongoose.connection.readyState === 0) {
|
|
// connect to mongo db
|
|
const mongoUri = config.mongo.host;
|
|
|
|
const promise = mongoose.connect(mongoUri, {
|
|
useNewUrlParser: true,
|
|
useUnifiedTopology: true
|
|
});
|
|
promise
|
|
.then(() => {
|
|
console.log('MongoDB is connected');
|
|
const portNum = process.env.PORT || 3000;
|
|
app.listen(portNum, () => {
|
|
console.log(`server listening on port ${portNum}`);
|
|
});
|
|
})
|
|
.catch(err => {
|
|
console.log(err);
|
|
console.log('MongoDB connection unsuccessful');
|
|
});
|
|
}
|
|
|
|
module.exports = app;
|