2018-02-15 19:16:54 +00:00
|
|
|
const path = require('path')
|
|
|
|
const express = require('express')
|
|
|
|
const webpack = require('webpack')
|
|
|
|
const webpackDevMiddleware = require('webpack-dev-middleware')
|
2018-03-04 02:49:11 +00:00
|
|
|
const apiProxyMiddleware = require('./apiProxyMiddleware')
|
|
|
|
const port = process.env.PORT || 3000
|
2018-02-15 19:16:54 +00:00
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
app.use(express.static(path.join(__dirname, 'public')))
|
|
|
|
|
|
|
|
const config = require('./webpack.config.js');
|
|
|
|
const compiler = webpack(config);
|
|
|
|
// Tell express to use the webpack-dev-middleware and use the webpack.config.js
|
|
|
|
// configuration file as a base.
|
|
|
|
app.use(webpackDevMiddleware(compiler, {
|
|
|
|
publicPath: config.output.publicPath
|
2018-03-04 02:49:11 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
app.use(apiProxyMiddleware)
|
2018-02-15 19:16:54 +00:00
|
|
|
|
|
|
|
app.get('*', function (req, res) {
|
|
|
|
res.sendFile(path.join(__dirname, 'public/index.html'))
|
|
|
|
})
|
|
|
|
|
2018-03-04 02:49:11 +00:00
|
|
|
// Serve the files on set port or port 3000.
|
|
|
|
app.listen(port, function () {
|
|
|
|
console.log('Metamaps listening on port ' + port + '\n')
|
2018-02-15 19:16:54 +00:00
|
|
|
});
|