-
Notifications
You must be signed in to change notification settings - Fork 0
/
express.mjs
35 lines (28 loc) · 1.07 KB
/
express.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import path from "node:path"
import express from "express"
//import cors from "cors"
import bodyParser from "body-parser"
import utils from "./express.utils.mjs"
const CWD = path.resolve(process.cwd())
const PUBLIC_DIR = path.join(CWD, 'public')
const BUILD_DIR = path.join(CWD, 'build')
const app = express()
let renderResponse;
if (process.env.NODE_ENV === 'production') {
//const renderForServer = (await import('./build/renderForServer')).default
renderResponse = utils.createProRenderResponse();
} else {
const clientConfig = (await import('./webpack.client.mjs')).default
const { devMiddleware, hotMiddleware } = await utils.useWebpack(app, clientConfig)
renderResponse = utils.createDevRenderResponse(devMiddleware)
}
app.use(bodyParser.json())
app.use('/static', express.static(BUILD_DIR))
app.use('/static', express.static(PUBLIC_DIR))
app.post('/write', utils.writeResponse)
app.post('/read', utils.readResponse)
app.post('/run', utils.runResponse)
app.get('/*', renderResponse)
app.listen(3000, '127.0.0.1', () => {
console.log('Listening: http://127.0.0.1:3000/')
})