MCPcopy Create free account
hub / github.com/artsy/force / startDevServer

Function startDevServer

src/dev.ts:16–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14const args = yargs(hideBin(process.argv)).argv as CLIArguments
15
16export async function startDevServer() {
17 // Wait for multienv to load envs
18 const { startServer } = require("./Server/startServer")
19
20 const app = express()
21
22 const { content } = await loadConfig({})
23
24 const rsbuild = await createRsbuild({
25 rsbuildConfig: content,
26 })
27
28 const rsbuildServer = await rsbuild.createDevServer()
29
30 // Get the output path of the server build
31 const stats = await rsbuildServer.environments.server.getStats()
32
33 const { outputPath } = stats.toJson({
34 all: true,
35 })
36
37 // Init RSBuild dev middleware
38 app.use(rsbuildServer.middlewares)
39
40 // Add server-side hot reloading
41 const mountAndReload = createReloadable(app, require)
42
43 mountAndReload(outputPath)
44
45 const httpServer = await startServer(app, () => {
46 const url = (() => {
47 const defaultURL = `http://localhost:${rsbuildServer.port}`
48
49 if (isString(args.open)) {
50 return args.open
51 }
52
53 return defaultURL
54 })()
55
56 rsbuildServer.afterListen()
57
58 logger.log(`[Force] Server started at ${url}`)
59
60 // Open the browser
61 if (args.open) {
62 execSync(`open ${url}`)
63 }
64 })
65
66 rsbuildServer.connectWebSocket({ server: httpServer })
67
68 return {
69 close: async () => {
70 await rsbuildServer.close()
71 httpServer.close()
72 },
73 }

Callers 1

dev.tsFile · 0.85

Calls 2

startServerFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected