Host static files

serve_static.ts 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.

// Copyright 2019 Yusuke Sakurai. All rights reserved. MIT license.
import { serveStatic } from "https://servestjs.org/@v0.36.0/serve_static.ts";
import { createApp } from "https://servestjs.org/@v0.36.0/app.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 });