Ask Your Question
3

What is the method for making Deno's standard http file_server monitor files?

asked 2023-06-16 05:02:46 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-16 05:03:02 +0000

devzero gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-16 05:02:46 +0000

Seen: 10 times

Last updated: Jun 16 '23