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

Function staticFile

packages/qwik-city/src/middleware/bun/index.ts:151–185  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

149 };
150
151 const staticFile = async (request: Request) => {
152 try {
153 const url = getRequestUrl(request, opts);
154
155 if (isStaticPath(request.method || 'GET', url)) {
156 const { filePath, content } = await openStaticFile(url);
157 // We know that it's in the static folder, but it could still be missing
158 // If we start the stream with a missing file, it will throw a 500 error during the stream
159 if (!(await content.exists())) {
160 return new Response('Not Found', {
161 status: 404,
162 headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Not-Found': url.pathname },
163 });
164 }
165
166 const ext = extname(filePath).replace(/^\./, '');
167
168 return new Response(await content.stream(), {
169 status: 200,
170 headers: {
171 'content-type': MIME_TYPES[ext] || 'text/plain; charset=utf-8',
172 'Cache-Control': opts.static?.cacheControl || 'max-age=3600',
173 },
174 });
175 }
176
177 return null;
178 } catch (e) {
179 console.error(e);
180 return new Response(String(e || 'Error'), {
181 status: 500,
182 headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Error': 'bun-server' },
183 });
184 }
185 };
186
187 return {
188 router,

Callers 6

handleFunction · 0.50
qwikAppFunction · 0.50
entry.deno.tsFile · 0.50
fetchFunction · 0.50

Calls 4

isStaticPathFunction · 0.85
extnameFunction · 0.85
getRequestUrlFunction · 0.70
openStaticFileFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…