-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (37 loc) · 1.24 KB
/
server.js
File metadata and controls
39 lines (37 loc) · 1.24 KB
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
import express from 'express';
import next from 'next';
import apiRoutes from 'api';
import config from 'config';
import compression from 'compression';
import cookieParser from 'cookie-parser';
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
import bodyParser from 'body-parser';
const app = next({ dev })
const handle = app.getRequestHandler()
// import getObjects from './common/request';
// import sendEmail from './common/email';
app.prepare()
.then(() => {
const server = express();
// serving static files
server.use(compression());
server.use(bodyParser.urlencoded({ extended: false }));
server.use(bodyParser.json());
server.use(cookieParser());
server.use('/api', apiRoutes);
server.post('/sendEmail', (req, res) => {
getObjects(config.private_settings_type).then((object) => {
sendEmail(req.body, object[0].metadata)
.then((response) => res.json({ success: true }))
.catch(e => res.status(500).send({ success: false}));
})
.catch(e => res.status(500).send(e))
});
server.get('*', (req, res) => handle(req, res))
// server
server.use(handle).listen(port, (err) => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})
})