(req: Request, res: Response, next: NextFunction)
| 59 | // dev server builds ssr's the starter app on-demand (don't do this in production) |
| 60 | const cache = new Map<string, Promise<QwikManifest>>(); |
| 61 | async 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 | |
| 117 | async function buildApp( |
| 118 | appDir: string, |
nothing calls this directly
no test coverage detected
searching dependent graphs…