Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
Refactor bin
Browse files Browse the repository at this point in the history
  • Loading branch information
mizchi committed Dec 21, 2018
1 parent 822b8b0 commit 7d10806
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions bin/start-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,43 @@ process.on("unhandledRejection", err => {
debug("Creating http server...");
const server = http.createServer();

createApp()
.then(app => {
(async () => {
try {
const app = await createApp();
server.on("request", app);

const port = +(process.env.PORT || 3000);
server.listen(port, () => {
debug(`Listening on port ${port}`);
});
})
.catch(err => {
} catch (err) {
debug(err);
process.exit(1);
});
}
})();

function createApp() {
async function createApp() {
const app = express();
return (development
(await development)
? setupAppForDevelopment(app)
: setupAppForProduction(app)
).then(() => {
app.use((req, res) => {
res.status(404).send("Not found");
});

if (development) {
app.use(errorhandler());
} else {
app.use((err, req, res, next) => {
res.status(500).send("Internal Server Error");
});
}
: setupAppForProduction(app);

return app;
app.use((req, res) => {
res.status(404).send("Not found");
});

if (development) {
app.use(errorhandler());
} else {
app.use((err, req, res, next) => {
res.status(500).send("Internal Server Error");
});
}

return app;
}

/* eslint-disable global-require, import/no-extraneous-dependencies, import/no-unresolved */
function setupAppForProduction(app) {
async function setupAppForProduction(app) {
const clientStats = require("../build/client/stats.json");
const serverRender = require("../build/server/main.js").default;
const promises = [];
Expand All @@ -72,7 +71,7 @@ function setupAppForProduction(app) {
return Promise.all(promises);
}

function setupAppForDevelopment(app) {
async function setupAppForDevelopment(app) {
const { MemoryStore } = require("express-session");
const webpack = require("webpack");
const webpackDevMiddleware = require("webpack-dev-middleware");
Expand Down

0 comments on commit 7d10806

Please sign in to comment.