Initial commit
This commit is contained in:
24
server/index.ts
Normal file
24
server/index.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import Koa from "koa";
|
||||
import serve from "koa-static";
|
||||
import path from "path";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
(async () => {
|
||||
const app = new Koa();
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
const koaWebpack = (await import("koa-webpack")).default;
|
||||
const config = (await import("../webpack.config")).default;
|
||||
const middleware = await koaWebpack({
|
||||
config,
|
||||
devMiddleware: { publicPath: "/" },
|
||||
});
|
||||
app.use(middleware);
|
||||
} else {
|
||||
app.use(serve(path.resolve(__dirname, "../client")));
|
||||
}
|
||||
console.info(
|
||||
`Server listening on ${process.env.PROTOCOL}://${process.env.HOSTNAME}:${process.env.PORT}`
|
||||
);
|
||||
app.listen(Number.parseInt(process.env.PORT), process.env.HOSTNAME);
|
||||
})().catch(err => console.log(err));
|
||||
Reference in New Issue
Block a user