-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdev-server.js
More file actions
29 lines (25 loc) · 755 Bytes
/
Copy pathdev-server.js
File metadata and controls
29 lines (25 loc) · 755 Bytes
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
import express from 'express'
const PORT = Number.parseInt(process.env.PORT || '3000')
const app = express()
app.disable('x-powered-by')
console.log('Starting development server')
const viteDevServer = await import('vite').then((vite) =>
vite.createServer({
server: { middlewareMode: true },
})
)
app.use(viteDevServer.middlewares)
app.use(async (req, res, next) => {
try {
const source = await viteDevServer.ssrLoadModule('./server/app.ts')
return await source.default(req, res, next)
} catch (error) {
if (typeof error === 'object' && error instanceof Error) {
viteDevServer.ssrFixStacktrace(error)
}
next(error)
}
})
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`)
})