MCPcopy
hub / github.com/QwikDev/qwik / handleApp

Function handleApp

starters/dev-server.ts:61–115  ·  view source on GitHub ↗
(req: Request, res: Response, next: NextFunction)

Source from the content-addressed store, hash-verified

59// dev server builds ssr's the starter app on-demand (don't do this in production)
60const cache = new Map<string, Promise<QwikManifest>>();
61async function handleApp(req: Request, res: Response, next: NextFunction) {
62 try {
63 let url;
64 try {
65 url = new URL(req.url, address);
66 } catch {
67 res.status(404).send();
68 return;
69 }
70 if (existsSync(url.pathname)) {
71 const relPath = relative(startersAppsDir, url.pathname);
72 if (!relPath.startsWith(".")) {
73 url.pathname = relPath;
74 }
75 }
76 const paths = url.pathname.split("/");
77 const appName = paths[1];
78 const appDir = join(startersAppsDir, appName);
79 if (!existsSync(appDir)) {
80 res.status(404).send(`❌ Invalid dev-server path: ${appDir}`);
81 return;
82 }
83
84 console.log(req.method, req.url, `[${appName} build/ssr]`);
85
86 const pkgPath = join(appDir, "package.json");
87 const pkgJson: PackageJSON = JSON.parse(readFileSync(pkgPath, "utf-8"));
88 const enableCityServer = !!pkgJson.__qwik__?.qwikCity;
89
90 let clientManifest = cache.get(appDir);
91 if (!clientManifest) {
92 clientManifest = buildApp(appDir, appName, enableCityServer);
93 cache.set(appDir, clientManifest);
94 }
95
96 const resolved = await clientManifest;
97 if (url.pathname.endsWith(".js")) {
98 res.set("Content-Type", "text/javascript");
99 } else {
100 res.set("Content-Type", "text/html");
101 }
102 if (enableCityServer) {
103 await cityApp(req, res, next, appDir);
104 } else {
105 await ssrApp(req, res, appName, appDir, resolved);
106 res.end();
107 }
108 } catch (e: any) {
109 console.error(e);
110 if (!res.headersSent) {
111 res.set("Content-Type", "text/plain; charset=utf-8");
112 res.send(`❌ ${e.stack || e}`);
113 }
114 }
115}
116
117async function buildApp(
118 appDir: string,

Callers

nothing calls this directly

Calls 9

relativeFunction · 0.85
joinFunction · 0.85
buildAppFunction · 0.85
cityAppFunction · 0.85
ssrAppFunction · 0.85
endMethod · 0.80
parseMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…