Skip to main content

Class: BaseStaticRoute

Defined in: service-core/src/routes/BaseStaticRoute.ts:58

The BaseStaticRoute class provides a single endpoint for serving static files from a designated path on the filesystem (e.g. ./public). Uses the path specified in the project configuration key static_files. Default is public.

Exposed endpoints:

NameHTTP MethodWhat it does
getGET /<base_path>/*Serves static files from the configured static_files.

!!Note!! that the BaseStaticRoute is not automatically registered with a server by default. You must create your own class that extends AdminRoute and apply the desired base path with @Route().

Example​

import { BaseStaticRoute, RouteDecorators } from "@rapidrest/service-core";
const { Route } = RouteDecorators;

@Route("/static")
export class StaticRoute extends BaseStaticRoute {}

Constructors​

Constructor​

new BaseStaticRoute(): BaseStaticRoute

Returns​

BaseStaticRoute

Properties​

routePrefix​

protected routePrefix: string = ""

Defined in: service-core/src/routes/BaseStaticRoute.ts:64

The URL prefix derived from @Route metadata at init time. E.g. @Route("/app/*") → prefix = "/app". Used to strip the prefix from req.path before resolving app page files, and to scope the dev-reload SSE endpoint.


staticDir​

protected readonly staticDir: string = "public"

Defined in: service-core/src/routes/BaseStaticRoute.ts:68

The location of the static files to serve. Defaults to ./public.

Methods​

get()​

get(req, res): Promise<any>

Defined in: service-core/src/routes/BaseStaticRoute.ts:108

Parameters​

req​

HttpRequest

res​

HttpResponse

Returns​

Promise<any>


init()​

protected init(): Promise<void>

Defined in: service-core/src/routes/BaseStaticRoute.ts:71

Returns​

Promise<void>