agent-relay-server 0.4.39 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -117,12 +117,36 @@ export function createFetchHandler(
117
117
  return Response.json({ error: "not found" }, { status: 404 });
118
118
  }
119
119
  const file = Bun.file(resolved);
120
- if (await file.exists()) return new Response(file);
120
+ if (await file.exists()) {
121
+ const headers = staticHeaders(requested);
122
+ return new Response(file, { headers });
123
+ }
121
124
 
122
125
  return Response.json({ error: "not found" }, { status: 404 });
123
126
  };
124
127
  }
125
128
 
129
+ function staticHeaders(pathname: string): Headers {
130
+ const headers = new Headers();
131
+ const contentType = staticContentType(pathname);
132
+ if (contentType) headers.set("Content-Type", contentType);
133
+ if (pathname === "/sw.js") {
134
+ headers.set("Cache-Control", "no-cache");
135
+ } else if (pathname === "/manifest.webmanifest") {
136
+ headers.set("Cache-Control", "no-cache");
137
+ }
138
+ return headers;
139
+ }
140
+
141
+ function staticContentType(pathname: string): string | undefined {
142
+ if (pathname.endsWith(".webmanifest")) return "application/manifest+json; charset=utf-8";
143
+ if (pathname.endsWith(".js")) return "text/javascript; charset=utf-8";
144
+ if (pathname.endsWith(".html")) return "text/html; charset=utf-8";
145
+ if (pathname.endsWith(".svg")) return "image/svg+xml";
146
+ if (pathname.endsWith(".png")) return "image/png";
147
+ return undefined;
148
+ }
149
+
126
150
  if (import.meta.main) {
127
151
  main().catch((error) => {
128
152
  console.error(error instanceof Error ? error.message : String(error));