-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (35 loc) · 1015 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const cors = require('cors')({ origin: true });
require('dotenv').config();
const firebaseAdmin = require('firebase-admin');
const serviceAccount = require('./api/config/service-account');
firebaseAdmin.initializeApp({
credential: firebaseAdmin.credential.cert(serviceAccount),
databaseURL: 'https://my-portal-e90f4.firebaseio.com',
});
const app = express();
const routes = require('./api/routes/index');
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cors);
app.use('/api/v1', routes);
app.use((req, res, next) => {
const error = new Error('Route Not Found');
error.status = 404;
next(error);
return res.status(404).send({
message: 'Route Not Found',
});
});
app.use((err, req, res) => {
res.status(err.status || 500);
res.json({
err: {
message: err.message,
},
});
});
module.exports = app;