Deno Deploy officially adds support for static files

Deno Deploy is built on the same underlying infrastructure as Deno CLI, allowing developers to develop locally without internet access. Prior to this, Deno Deploy only supported dynamic files and did not support static resources such as CSS files, client-side JS files, and images. The previous approach was to encode these static resources into JS code, or manually add them to a CDN, or pull files from a GitHub repository.

However, just yesterday, on February 10th, Beijing time, the official blog of Deno Deploy announced that it will add first-class support for static files. Users can use Deno's file system API to support static files.

insert image description here

On Deno Deploy, the actual file serving is still controlled by code running on the edge, so users can control all responses, including static files. For example:

  • Only serve files to logged in users
  • Add CORS header content to the file
  • Some dynamic content files can also be modified at the edge before the file is browsed
  • Provide corresponding files according to the user's browser
  • In Deno Deploy, static files are not a completely separate system

List of filesystem APIs currently supported by Deno Deploy:

  • Deno.readFile reads the file into memory
  • Deno.readTextFile reads the file into memory as a UTF-8 string
  • Deno.readDir gets a list of files and folders in a folder
  • Deno.open opens a file for reading in chunks (for streaming)
  • Deno.stat get information about a file or folder (get size or type)
  • Deno.lstat is the same as above, but does not follow symlinks
  • Deno.realPath gets the path of a file or folder after resolving symlinks

For more details, you can view Deno Deploy official blog: Static Files on Deno Deploy

Guess you like

Origin blog.csdn.net/mengyidan/article/details/122876416