-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (22 loc) · 910 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
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const helmet = require('helmet')
const morgan = require('morgan')
const errorHandlingMiddleware = require('./src/middleware/error-handling.middleware')
const authenticate = require('./src/middleware/authentication.middleware')
const asyncWrapperHelper = require('./src/helpers/async-wrapper.helper')
const emailController = require('./src/controllers/email.controller')
app.use(bodyParser.json())
app.use(helmet())
app.use(morgan('tiny'))
// Register endpoint
app.post('/email', authenticate, asyncWrapperHelper(emailController))
app.use('**', (req, res) => {
res.status(404).json('👋 These are not the droids you\'re looking for!')
})
// Error Handling
app.use(errorHandlingMiddleware)
app.listen(process.env.PORT, () => {
console.log(`Node Email API running on port ${process.env.PORT}`)
})