(
req: IncomingMessage | Http2ServerRequest,
res: ServerResponse,
next: (e?: any) => void
)
| 94 | }; |
| 95 | |
| 96 | const staticFile = async ( |
| 97 | req: IncomingMessage | Http2ServerRequest, |
| 98 | res: ServerResponse, |
| 99 | next: (e?: any) => void |
| 100 | ) => { |
| 101 | try { |
| 102 | const origin = computeOrigin(req, opts); |
| 103 | const url = getUrl(req, origin); |
| 104 | if (isStaticPath(req.method || 'GET', url)) { |
| 105 | const pathname = url.pathname; |
| 106 | let filePath: string; |
| 107 | if (basename(pathname).includes('.')) { |
| 108 | filePath = join(staticFolder, pathname); |
| 109 | } else if (opts.qwikCityPlan.trailingSlash) { |
| 110 | filePath = join(staticFolder, pathname + 'index.html'); |
| 111 | } else { |
| 112 | filePath = join(staticFolder, pathname, 'index.html'); |
| 113 | } |
| 114 | const ext = extname(filePath).replace(/^\./, ''); |
| 115 | const stream = createReadStream(filePath); |
| 116 | stream.on('error', next); |
| 117 | |
| 118 | const contentType = MIME_TYPES[ext]; |
| 119 | |
| 120 | if (contentType) { |
| 121 | res.setHeader('Content-Type', contentType); |
| 122 | } |
| 123 | |
| 124 | if (opts.static?.cacheControl) { |
| 125 | res.setHeader('Cache-Control', opts.static.cacheControl); |
| 126 | } |
| 127 | |
| 128 | stream.pipe(res); |
| 129 | |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | return next(); |
| 134 | } catch (e) { |
| 135 | console.error(e); |
| 136 | next(e); |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | return { |
| 141 | router, |
nothing calls this directly
no test coverage detected
searching dependent graphs…