-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFE] @std/http/file_server - Allow to modify file contents on-the-fly #6380
Comments
Doesn't sounds like a common needs to a static file server. I'd recommend you should read the file on your own handler, modify it, and respond: Deno.serve(async (req) => {
const path = new URL(req.url).pathname;
let text: string
try {
text = await Deno.readTextFile("." + path);
} catch {
return new Response("Not found", { status: 404 });
}
if (condition(req)) {
return new Response(text, { headers: { "content-type": "text/html" } });
}
return new Response(addHeader(text), { headers: { "content-type": "text/html" } });
}); |
Isn't the purpose of Anyhow thanks for the example code you provided and i will try to make use of it...
All in all, i'm still lost as a new |
I guess what you are looking for is web frameworks (such as hono, fresh, lume, etc)
Yeah, I meant |
Is your feature request related to a problem? Please describe.
It would be nice (i would like tobe able) if we could modify the file contents of certain files served "On-The-Fly", eg, before actual sending of the contents.
Excuse me for still being a total noob wrt
deno
,TypeScript
, et all...I would like to automatically inject, for example the below, inside the
<head>
tag of html files that will be served:Describe the solution you'd like
Somekind of hook/callback we could add to the function call, that modifies the text-data from the file before that data is send out, depending on file type and name.
Usage inside a module:
Or from command line:
$ file-server --filter=./myFilter.mts ./src
The above would process each request and serve the file(s) that is/are requested
filter
.Describe alternatives you've considered
No idea yet, as i'm still in the process of reading
deno
docs and learningTypeScript
🤷♀If what i describe is already possible please show me the way to do it with an example and if possible add it to the docs. 😉
The text was updated successfully, but these errors were encountered: