The method for making Deno's standard http fileserver monitor files is by using the watchFileSystem option. Here's an example of how to use the fileserver and watchFileSystem options together:
import { serve } from 'https://deno.land/std/http/server.ts';
import { fileServer } from 'https://deno.land/std/http/file_server.ts';
const server = serve({ port: 8000 });
// Serving files
for await (const req of server) {
// The root directory being served
const root = './public';
// Enable file watching and automatic refresh
const fileServerConfig = {
...fileServer(root),
watchFileSystem: true
};
// Serve files with the file server
const requestHandler = fileServer(fileServerConfig);
requestHandler(req);
}
In this example, the file_server will watch the file system for changes and automatically refresh the served files when a change is detected. The watchFileSystem
option is set to true
to enable this behavior.
Asked: 2023-06-16 05:02:46 +0000
Seen: 10 times
Last updated: Jun 16 '23