Host static files

serveStatic is a built-in middleware for hosting static files (html, image, stylesheets and more).

In the example below, all files in ./public directories are automatically served if request path matches file. For instance, ./public/index.csswill be served as http://example.com/index.css.

If no files found on requested path, request will be passed into the next middleware.

import { createApp, serveStatic } from "https://servestjs.org/@v1.1.0/mod.ts";
const app = createApp();
// All requests will be processed and matched files in "public" directory
// are served automatically
// Otherwise, request will be passed to next handler
app.use(serveStatic("./public"));
app.listen({ port: 8899 });