forked from Arc-angelHack/onearcBackend_revised
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (51 loc) · 1.72 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const express = require('express')
const bodyParser = require('body-parser')
const morgan = require('morgan')
const cors = require('cors')
const app = express()
const {
PORT = 5000, NODE_ENV = 'development'
} = process.env
if (NODE_ENV === 'development') {
require('dotenv').load()
app.use(morgan('dev'))
}
app.use(bodyParser.json())
app.use(cors())
// user's info
app.use('/api/users', require('./src/routes/users'))
app.use('/profile/personal', require('./src/routes/personal'))
app.use('/profile/medical', require('./src/routes/medical'))
// incidents
app.use('/incidents', require('./src/routes/incidents'))
app.use('/incidents/byuser', require('./src/routes/incidents_user')) // incidents created by a user
// sos help requests
app.use('/sosrequests', require('./src/routes/sos_requests'))
// resources
app.use('/api/resOffer', require('./src/routes/resource_offers')) // CRUD for resource offers
app.use('/api/resRequest', require('./src/routes/resource_requests')) // CRUD for resource requests (similar to above; can merge eventually)
app.use('/api/resTrans', require('./src/routes/resource_transactions')) // Create & Delete for Resource Transactions
app.use((err, req, res, next) => {
if (NODE_ENV === 'development') console.error(err)
const message = `Something went wrong.`
const {
status = 500, error = message
} = err
res.status(status).json({
status,
error
})
})
app.use((req, res, next) => {
const status = 404
const error = `Could not ${req.method} ${req.url}`
next({
status,
error
})
})
if (NODE_ENV !== 'testing') {
const listener = () => console.log(`Listening on port ${PORT}!`)
app.listen(PORT, listener)
}
module.exports = app