{"size": 1823, "ext": "js", "max_stars_repo_path": "front-end/bin/server.js", "max_stars_repo_name": "MartinYounghoonKim/foodLive", "max_stars_repo_stars_event_min_datetime": "2020-08-16T12:24:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-16T12:24:53.000Z", "max_issues_repo_path": "front-end/bin/server.js", "max_issues_repo_name": "MartinYounghoonKim/foodLive", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "front-end/bin/server.js", "max_forks_repo_name": "MartinYounghoonKim/foodLive", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.0428571429, "max_line_length": 94, "alphanum_fraction": 0.5995611629}
/**
 * @description Express server
 */
const express = require('express');
const path = require('path');

const app = express();

const http = require('http');
const server = http.createServer(app);
/**
 * @description env settings
 */
const isProduction = process.env.NODE_ENV === 'production';
const port = isProduction ? process.env.PORT : 4000;

const fs = require('fs');

if (!isProduction) {
    /**
     * @description webpack HMR module
     */
    const webpack = require('webpack');
    const webpackDevMiddleware = require('webpack-dev-middleware');
    const webpackHotMiddleware = require('webpack-hot-middleware');
    const webpackConfig = require('../build/dev.server.config.js');
    const compiler = webpack(webpackConfig);

    const middleware = webpackDevMiddleware(compiler, {
        noInfo: true,
        hot: true,
        publicPath: '/dist/',
        filename: 'bundle.js',
        quiet: false,
        lazy: false,
        watchOptions: {
            aggregateTimeout: 300,
            poll: true
        },
        stats: {
            colors: true,
        },
        historyApiFallback: true,
    });

    app.use(middleware);
    app.use(webpackHotMiddleware(compiler, {
        log: console.log,
        path: '/__webpack_hmr',
        heartbeat: 10 * 1000,
    }));
    app.get('/', function(req, res) {
        res.send('<body><div id="app"></div><script src=\'dist/bundle.js\'></script></body>');
    });
} else {
    const template = fs.readFileSync('./dist/index.html', 'utf-8');

    app.get('/', function(req, res) {
        res.send(template);
    });
}
app.use(express.static( "dist"));

server.listen(port, function() {
    const host = server.address().address;
    const port = server.address().port;

    console.log(`Express server has started on port:${host}:${port}`);
});
