{"size": 1344, "ext": "js", "max_stars_repo_path": "server/dev.js", "max_stars_repo_name": "dimasjt/moment", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/dev.js", "max_issues_repo_name": "dimasjt/moment", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/dev.js", "max_forks_repo_name": "dimasjt/moment", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.3529411765, "max_line_length": 94, "alphanum_fraction": 0.7075892857}
import express from 'express';
import morgan from 'morgan';
import responseTime from 'response-time';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpack from 'webpack';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';

import fs from 'fs';
import path from 'path';

import webpackConfig from './webpack/dev';
import database from './config/database';
import api from './api';

const logFile = path.resolve(__dirname, '../log/dev.log');
const logDir = path.resolve(__dirname, '../log');
const accessLogStream = fs.createWriteStream(logFile, { flags: 'a' });
const PORT = process.env.PORT || 3000;

fs.existsSync(logDir) || fs.mkdirSync(logDir);

database();

const app = express();
const compiler = webpack(webpackConfig);
const middleware = webpackDevMiddleware(compiler, {
  publicPath: '/assets',
  stats: {
    color: true,
  },
});

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(morgan('combined', { stream: accessLogStream }));
app.use(responseTime());
app.use(middleware);

app.use('/api', api);

app.get('*', (req, res) => {
  res.write(middleware.fileSystem.readFileSync(path.resolve(__dirname, 'assets/index.html')));
  res.end();
});

app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});
