App
Create
To create a web server with ovr, initialize a new App instance:
import { App } from "ovr";
const app = new App();
The App API is inspired by and works similar to frameworks such as Express, Koa, and Hono.
Options
The following values can be configured when creating the App.
Trailing Slash
ovr handles trailing slash redirects automatically, you can customize the redirect preference.
new App({ trailingSlash: "always" });
CSRF
ovr comes with basic cross-site request forgery protection.
new App({ csrf: false }); // disables the built-in protection
Form
new App({
form: {
memory: 12 * 1024 * 1024, // increase to 12MB
payload: 1024 ** 3, // increase to 1GB
parts: 4, // only accept up to 4 parts
},
});
Use
Use the use method to register routes and middleware to your application.
app.use(page); // single
app.use(page, login, mw); // multiple
app.use({ page, login, mw }); // object
app.use([page, login, mw]); // array
// any combination of these also works
This makes it easy to create a module of routes and/or middleware,
// home.tsx
import { Route } from "ovr";
export const page = Route.get("/", (c) => {
// ...
});
export const login = Route.post((c) => {
// ...
});
and then use them all at once:
// app.tsx
import * as home from "./home";
app.use(home); // uses all exports
Fetch
Use the fetch method to create a Response, this is the Request handler for your application.
const response = await app.fetch("https://example.com");
Head requests
ovr automatically handles HEAD requests, each will be routed to the corresponding GET route. Middleware will execute but Context.res.body will cleaned up and set to null before building the final response.