-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·39 lines (30 loc) · 1.05 KB
/
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
36
37
38
39
/* eslint-disable no-console */
require('dotenv').config();
const express = require('express');
const compression = require('compression');
const bodyParser = require('body-parser');
const { sendEmail } = require('./src/contact/sendEmail');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpack = require('webpack');
const webpackConfig = require('./webpack.production.config.js');
const app = express();
const compiler = webpack(webpackConfig);
app.use(compression());
app.use(webpackDevMiddleware(compiler, {
filename: 'bundle.js',
publicPath: '/',
stats: {
colors: true,
},
historyApiFallback: true,
}));
app.use(express.static(`${__dirname}/www`));
app.use(express.static(`${__dirname}/resources`));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const serverPort = process.env.PORT || 3000;
app.post('/sendMessage', sendEmail);
const server = app.listen(serverPort, () => {
const { address, port } = server.address();
console.log('App listening at http://%s:%s', address, port);
});