+ Added [router] and cleaned some code

This commit is contained in:
Alexis
2020-03-23 18:35:13 +01:00
parent bd141eeda3
commit 144eb31392
4 changed files with 53 additions and 44 deletions

View File

@@ -1,32 +1,24 @@
// MODULES
const express = require('express');
const connection = require('./database/connection');
const getSpells = connection.getSpells;
const closeConnection = connection.closeConnection;
const db = connection.db;
//
const routes = require('./routes');
// CONSTANTS
const port = 2814;
// APP
app = express();
const server = app.listen(port, () => {console.log(`App listening on port ${port}`)});
const server = app.listen( port, () => {console.log(`App listening on port ${port}`)});
// getSpells().then((v) => {
// console.log(v);
// }).catch(r => {
// console.log(r);
// })
app.use('/spells', routes.spells);
app.route('/spells')
.get((req, res, next) => {
getSpells().then(v => {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({spells : v}));
})
})
// On process exit
// On process kill with SIGINT
process.on('SIGINT', () => {
closeConnection();
db.end();
server.close();
})
console.log('Server closed');
})