MCPcopy
hub / github.com/redfin/react-server / startStaticJsServer

Function startStaticJsServer

packages/react-server-cli/src/commands/start.js:131–171  ·  view source on GitHub ↗
(compiler, port, bindIp, longTermCaching, httpsOptions)

Source from the content-addressed store, hash-verified

129// static compiled JavaScript. returns an object with two properties, started and stop;
130// see the default function doc for explanation.
131const startStaticJsServer = (compiler, port, bindIp, longTermCaching, httpsOptions) => {
132 const server = express();
133 const httpServer = httpsOptions ? https.createServer(httpsOptions, server) : http.createServer(server);
134 return {
135 stop: serverToStopPromise(httpServer),
136 started: new Promise((resolve, reject) => {
137 compiler.run((err, stats) => {
138 const error = handleCompilationErrors(err, stats);
139 if (error) {
140 reject(error);
141 return;
142 }
143
144 if (stats) {
145 logger.debug("Successfully compiled static JavaScript.");
146 }
147
148 // TODO: make this parameterized based on what is returned from compileClient
149 server.use('/', compression(), express.static(`__clientTemp/build`, {
150 maxage: longTermCaching ? '365d' : '0s',
151 }));
152 logger.info("Starting static JavaScript server...");
153
154 httpServer.on('error', (e) => {
155 console.error("Error starting up JS server");
156 console.error(e);
157 reject(e)
158 });
159 httpServer.listen(port, bindIp, (e) => {
160 if (e) {
161 reject(e);
162 return;
163 }
164
165 logger.info(`Started static JavaScript server over ${httpsOptions ? "HTTPS" : "HTTP"} on ${bindIp}:${port}`);
166 resolve();
167 });
168 });
169 }),
170 };
171};
172
173// given a webpack compiler and a port, start a webpack dev server that is ready
174// for hot reloading at http://localhost:port/. note that the webpack compiler

Callers

nothing calls this directly

Calls 2

serverToStopPromiseFunction · 0.85
handleCompilationErrorsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…