-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathserver.mjs
More file actions
35 lines (26 loc) · 822 Bytes
/
server.mjs
File metadata and controls
35 lines (26 loc) · 822 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
30
31
32
33
34
35
import express from "express";
import { createRsbuild, loadConfig } from "@rsbuild/core";
export async function startDevServer() {
const { content } = await loadConfig({});
// Init Rsbuild
const rsbuild = await createRsbuild({
rsbuildConfig: content,
});
const app = express();
// Create Rsbuild DevServer instance
const rsbuildServer = await rsbuild.createDevServer();
// Apply Rsbuild’s built-in middlewares
app.use(rsbuildServer.middlewares);
const httpServer = app.listen(rsbuildServer.port, () => {
// Notify Rsbuild that the custom server has started
rsbuildServer.afterListen();
});
rsbuildServer.connectWebSocket({ server: httpServer });
return {
close: async () => {
await rsbuildServer.close();
httpServer.close();
},
};
}
startDevServer();