-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (28 loc) · 904 Bytes
/
server.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
// Setup ENV variables
require('dotenv').config()
// Setup the server
const express = require('express')
const app = express()
const cors = require('cors')
const morgan = require('morgan')
// Set port, fallback to 3000 if not defined in .env
const PORT = process.env.PORT || 3000
// Setup HTTP logging with Morgan
app.use(morgan('tiny'))
// Enable CORS (change to whitelist before production)
app.use(cors())
// Enable JSON and URL encoded body parsing
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
// Setup routes to be accessible at /api
const routes = require('./routes')
app.use('/api/', routes)
app.get('/', (req, res) => res.send('Hello world!'))
// Start the server
app.listen(PORT, () => {
if (process.env.ENVIRONMENT === 'dev') {
console.log(`Server started on http://localhost:${PORT}`)
} else {
console.log(`Server started on port ${PORT}`)
}
})