-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (23 loc) · 899 Bytes
/
index.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
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors')
const helmet = require('helmet')
const resultRouter = require('./routes/result')
const app = express();
app.use(express.json())
app.use(cors());
app.use(helmet())
app.get('/', (req, res, next) => {
res.send('<h1>This is an API used for Antigen and Antibody results</h1><p>Go to route /result/results to see all of the results</p> <footer> <small>© Copyright 2021, James Domingo. All Rights Reserved</small> </footer>')
})
app.use('/result', resultRouter)
app.use((error, req, res, next) => {
console.log(error);
const status = error.statusCode || 500;
const message = error.message;
res.status(status).json({message: message})
})
mongoose.connect(process.env.DB_URI)
.then(result => {
app.listen(process.env.PORT || 5000);
}).catch(err => console.log(err))