add server

This commit is contained in:
Francesco Esposito 2019-08-15 23:24:43 +02:00
parent dfa50e0636
commit c20d67455e
1 changed files with 33 additions and 0 deletions

33
src/server.js Normal file
View File

@ -0,0 +1,33 @@
import express from 'express';
import routes from './routes';
import logger from './logger';
const app = express();
app.use('/api/weather', routes);
app.get('/', (req, res) => {
res.send('umbrello-api');
});
app.get('*', (req, res) => {
logger.error(`404 ${req.path}`);
res.send(404).send();
});
app.listen(3000, () => {
logger.info('Server started');
});
process
.on('unhandledRejection', (reason) => logger.error(reason))
.on('uncaughtException', (err) => {
logger.error(err);
process.exit(1);
})
.on('SIGINT', () => {
logger.info('Server stopped');
process.exit(0);
});