Static Files

Harpia makes it simple to serve static files such as images, stylesheets, or client-side JavaScript.

Configuration

To serve static files, use the app.static() method and pass the name of your static directory (relative to your project’s root).

import harpia from "@harpiats/core";

const app = harpia();

// Serve all files from the "public" directory
app.static("public");

When a request is made, Harpia will check if a file matching the URL path exists in the static directory. If it does, the file is returned immediately. If not, the request continues to your router and middlewares.

Usage in Views

Once configured, you can reference your static files directly in your HTML templates or client-side code from the root URL.

For example, if you have a file at public/css/style.css:

<link rel="stylesheet" href="/css/style.css">

If you have an image at public/images/logo.png:

<img src="/images/logo.png" alt="Harpia Logo">