Skip to main content

veryfront

Configuration, server bootstrap, routing, data fetching, and input validation.

Import

import {
  defineConfig,
  json,
  notFound,
  redirect,
  getEnv,
  createValidatedHandler,
} from "veryfront";

Examples

Configuration

import { defineConfig } from "veryfront";

export default defineConfig({
  // your project config
});

API routes

import { json } from "veryfront";
import type { APIContext, APIResponse } from "veryfront";

export function GET(ctx: APIContext): APIResponse {
  return json({ message: "Hello" });
}

Data loading

import { notFound } from "veryfront";
import type { DataContext } from "veryfront";

export function getServerData(ctx: DataContext) {
  if (!ctx.params.id) throw notFound();
  return { title: "Page" };
}

Exports

Components

NameDescription
CommonSchemasBuilt-in Zod schemas (email, URL, etc.)
INPUT_VALIDATION_FAILEDHTTP request input validation failures (replaces ValidationError)

Functions

NameDescription
apiNotFound404 Not Found response
apiRedirectRedirect response
badRequest400 Bad Request response
createHandlerCreate HTTP request handler
createValidatedHandlerCreate a validated API handler wrapper that auto-validates body/query with Zod schemas
createValidationErrorCreate an input validation error.
defineConfigDefine project configuration
forbidden403 Forbidden response
getEnvRead environment variable (typed)
jsonJSON response helper
notFoundThrow 404 in data loaders
parseFormDataParse multipart form data
parseJsonBodyParse and validate JSON body
parseQueryParamsParse and validate query params
redirectThrow redirect in data loaders
sanitizeDataSanitize data to prevent XSS and prototype pollution attacks.
serverError500 Internal Server Error response
startServerStart a Veryfront server in development or production mode.
toNodeHandlerConvert a Web API request handler into a Node.js HTTP request listener.
unauthorized401 Unauthorized response

Types

NameDescription
APIContextAPI route handler context
APIHandlerAPI route handler signature
APIResponseAPI handler response type
APIRouteRoute with method handlers
DataContextgetServerData context
InferGetServerDataPropsUtility type to infer props from a page with data
MDXFrontmatterParsed MDX frontmatter
PageContextPage runtime context
PageWithDataPage with data fetching capabilities
StartServerOptionsServer options. Defaults to development mode with HMR.
StaticPathsResultgetStaticPaths return type
ValidatedHandlerConfigcreateValidatedHandler config
ValidatedHandlerFunctionHandler with validated inputs
VeryfrontConfigProject configuration shape
VeryfrontHandlerWeb API request handler with WebSocket upgrade and HMR helpers.
VeryfrontServerRunning server instance with lifecycle controls.