-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-test.js
44 lines (38 loc) · 1.2 KB
/
server-test.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
/* @flow */
// Load .env file in development
if (process.env.NODE_ENV !== 'production') require('dotenv').config()
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const authMiddleware = require('./middleware/auth')
const server = express()
// Middleware Plugins
server.use(bodyParser.json()) // Allows me to have JSON uploads (POST/PATCH/PUT)
server.use(bodyParser.urlencoded({ extended: false })) // Allow url encoded content
server.use(cors()) // Allow other origins to access, i.e our react front-end
server.use(authMiddleware.initialize) // Kick passport off
// Routes
server.use('/', [
require('./routes/auth'),
require('./routes/recipient'),
require('./routes/message'),
require('./routes/notification'),
require('./routes/announcement'),
require('./routes/sms'),
require('./routes/email'),
require('./routes/fileUpload')
])
// Error handler
server.use((error, req, res, next) => {
res.json({
error: {
message: error.message
}
})
})
// Start the server
server.listen(7001, error => {
if (error) console.error('Error starting', error)
else console.log('Test Server Started at http://localhost:7001')
})
module.exports = server