MCPcopy Create free account
hub / github.com/adobe/react-spectrum / start

Function start

packages/dev/storybook-builder-parcel/preset.mjs:29–82  ·  view source on GitHub ↗
({options, router})

Source from the content-addressed store, hash-verified

27let watcherSubscription;
28
29export async function start({options, router}) {
30 const parcel = await createParcel(options, true);
31
32 // Storybook's CLI runs an Express-style server on :9003 (the user-facing
33 // dev URL). Parcel's own dev server runs on :3000 to serve iframe.html and
34 // the bundle assets. We mount a reverse proxy on Storybook's router so that
35 // any request that isn't the manager's own /index.html falls through to
36 // Parcel. If Parcel returns 404 or HTML for a non-iframe URL we hand the
37 // request back to next() so Storybook's manager middleware can handle it.
38 router.use(async (req, res, next) => {
39 if (req.url === '/' || req.url === '/index.html') return next();
40
41 const proxy = createProxyMiddleware({
42 target: 'http://localhost:3000/',
43 selfHandleResponse: true,
44 logLevel: 'warn',
45 onProxyRes(proxyRes, req, res) {
46 if (
47 proxyRes.statusCode === 404 ||
48 (proxyRes.headers['content-type']?.startsWith('text/html') &&
49 !req.url.startsWith('/iframe.html'))
50 ) {
51 return next();
52 }
53 res.statusCode = proxyRes.statusCode;
54 for (const header in proxyRes.headers) {
55 res.setHeader(header, proxyRes.headers[header]);
56 }
57 proxyRes.pipe(res);
58 }
59 });
60
61 const {socket, connection} = req;
62 req.socket = null;
63 req.connection = null;
64 await proxy(req, res, next);
65 req.socket = socket;
66 req.connection = connection;
67 });
68
69 watcherSubscription = await parcel.watch();
70 process.on('SIGINT', async () => {
71 await watcherSubscription?.unsubscribe();
72 process.exit();
73 });
74
75 return {
76 async bail() {
77 await watcherSubscription?.unsubscribe();
78 },
79 stats: {},
80 totalTime: 0
81 };
82}
83
84export async function build({options}) {
85 const parcel = await createParcel(options);

Callers

nothing calls this directly

Calls 1

createParcelFunction · 0.85

Tested by

no test coverage detected