A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.deno.com/examples/http_server_files/ below:

HTTP server: Serving files

HTTP server: Serving files

An example of a HTTP server that serves files.

import { serveDir, serveFile } from "jsr:@std/http/file-server";
Deno.serve((req: Request) => {
  const pathname = new URL(req.url).pathname;

  if (pathname === "/simple_file") {
    return serveFile(req, "./path/to/file.txt");
  }

  if (pathname.startsWith("/static")) {
    return serveDir(req, {
      fsRoot: "public",
      urlRoot: "static",
    });
  }

  return new Response("404: Not Found", {
    status: 404,
  });
});

Run this example locally using the Deno CLI:

deno run -N -R https://docs.deno.com/examples/scripts/http_server_files.ts
Did you find what you needed?

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4