Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* eslint no-console: 0 */
- const path = require('path');
- const express = require('express');
- const webpack = require('webpack');
- const webpackMiddleware = require('webpack-dev-middleware');
- const webpackHotMiddleware = require('webpack-hot-middleware');
- const config = require('./webpack.config.js');
- const isDeveloping = process.env.NODE_ENV !== 'production';
- const port = isDeveloping ? 3000 : process.env.PORT;
- var elasticsearch = require('elasticsearch');
- var client = new elasticsearch.Client({
- host: 'localhost:9200',
- log: 'trace'
- });
- const app = express();
- if (isDeveloping) {
- const compiler = webpack(config);
- const middleware = webpackMiddleware(compiler, {
- publicPath: config.output.publicPath,
- contentBase: 'src',
- stats: {
- colors: true,
- hash: false,
- timings: true,
- chunks: false,
- chunkModules: false,
- modules: false
- }
- });
- app.use(middleware);
- app.use(webpackHotMiddleware(compiler));
- app.get('*', function response(req, res) {
- res.write(middleware.fileSystem.readFileSync(path.join(__dirname, 'dist/index.html')));
- res.end();
- });
- } else {
- app.use(express.static(__dirname + '/img'));
- app.get('*', function response(req, res) {
- res.sendFile(path.join(__dirname, 'dist/index.html'));
- res.json({ message: "I'm just testing to see if this works" });
- res.send({"data": 1});
- res.end();
- });
- }
- app.get('/api/home', (req, res) => {
- res.json({ message: "I'm just testing to see if this works" });
- res.status(200);
- res.end();
- });
- app.get('/api/home', (req, res) => {
- res.json({ message: "I'm just testing to see if this works" });
- });
- app.listen(port, '0.0.0.0', function onStart(err) {
- if (err) {
- console.log(err);
- }
- console.info('==> 🌎 Listening on port %s. Open up http://0.0.0.0:%s/ in your browser.', port, port);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement