Skip to content

Commit 13264fe

Browse files
committed
remove magic values use config instead
1 parent 878b8c6 commit 13264fe

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

server/config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ const isProd = env.NODE_ENV === "production";
55
const isDev = env.NODE_ENV === "development";
66

77
// do not use isProd, isDev ..etc in render.tsx
8+
// tslint:disable:object-literal-sort-keys
89
export const config = {
910
env: env.NODE_ENV,
11+
serverHost: env.SERVER_HOST || "localhost",
12+
serverPort: env.SERVER_PORT || 3000,
1013
isDev,
1114
isProd,
1215
staticPath: isProd && path.resolve(__dirname, "../client")

server/server.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const app = express();
99
app.use(serveFavicon(path.resolve(config.staticPath, "favicon.ico")));
1010
app.use("/static/", express.static(config.staticPath));
1111

12-
if (process.env.NODE_ENV === "development") {
12+
if (!config.isProd) {
1313

1414
// tslint:disable:no-var-requires
1515
const webpack = require("webpack");
@@ -44,14 +44,14 @@ if (process.env.NODE_ENV === "development") {
4444

4545
Loadable.preloadAll()
4646
.then(() => {
47-
app.listen(3000, (err: any) => {
47+
app.listen(config.serverPort, (err: any) => {
4848
if (err) {
4949
// tslint:disable-next-line:no-console
5050
return console.error(err);
5151
}
5252
// tslint:disable-next-line:no-console
53-
console.log("running at http://localhost:3000");
53+
console.log(`running at http://localhost:${config.serverPort}`);
5454
// tslint:disable-next-line:no-console
55-
console.log(`environemt: ${process.env.NODE_ENV}`);
55+
console.log(`environemt: ${config.env}`);
5656
});
5757
});

0 commit comments

Comments
 (0)