///
///
import type { Application as ExpressApp } from 'express';
import type { default as Koa, Context } from 'koa';
import type http from 'http';
import type { Readable } from 'stream';
import type { DirectToCoreProxy, NormalizedLwrGlobalConfig, RuntimeContext, RuntimeEnvironment } from './index.js';
export type ServerTypes = 'koa' | 'express' | 'fs';
export type ServerTypeImpl = T extends 'koa' ? Koa : T extends 'express' ? ExpressApp : T extends 'fs' ? LwrDispatcher : never;
export interface FsContext extends Context {
fs?: {
headers?: http.IncomingHttpHeaders;
body?: any;
stream?: any;
metadata?: any;
type?: string;
};
}
export interface LwrDispatcher {
dispatchUrl(url: string, method: string, lang: string): Promise;
}
export interface InternalAppServer {
/**
* For external consumers only. Internally we should only be interacting with the interface
* and not the underlying implementation to ensure that we maintain compatibility with each server type.
*/
getImpl(): ServerTypeImpl;
getInternalRequestKey(): string;
createHttpServer(): http.Server;
use(middleware: MiddlewareFunction): void;
all(path: string | Array, middleware: MiddlewareFunction): void;
get(path: string | Array, middleware: MiddlewareFunction): void;
post(path: string | Array, middleware: MiddlewareFunction): void;
initRoutes(): void;
getRegexWildcard(): string;
}
export type InternalAppServerOptions = {
app?: ServerTypeImpl;
basePath?: string;
caseSensitiveRoutes?: boolean;
};
export interface InternalAppServerConstructable {
new (options: InternalAppServerOptions): InternalAppServer;
}
export interface MiddlewareFunction {
(req: MiddlewareRequest, res: MiddlewareResponse, next: Function): void;
}
export type Headers = http.IncomingHttpHeaders;
export interface MiddlewareRequest {
params: any;
originalUrl: string;
path: string;
query: any;
body: any;
method: string;
headers: Headers;
protocol: string;
locale: string;
basePath: string;
acceptsLanguages(): string[];
get(field: string): string | undefined;
cookie(name: string): string | undefined;
/**
* Return true if the request has a `json` query parameter
*/
hasJsonParam(): boolean;
/**
* Return JSON if:
* - the URI contains the "json" query parameter
* - the Accept header explicitly requests "application/json"
*/
isJsonRequest(): boolean;
/**
* Return true if the request was initiated by static generation
*/
isSiteGeneration(): boolean;
/**
* Return false when both Accept and JSON query param are applied, but do not semantically match
*/
validateJsonRequest(): boolean;
/**
* Return true when the environment path parameter exists and is supported
*/
validateEnvironmentRequest(config: NormalizedLwrGlobalConfig): boolean;
/**
* Return true when the api version path parameter exists and is supported
*/
validateApiVersion(config: NormalizedLwrGlobalConfig): boolean;
/**
* Use the request parameters to resolve the runtime context(ie. environment and parameters)
*/
getRuntimeContext(defaultRuntimeEnvironment: RuntimeEnvironment): RuntimeContext;
/**
* Resolve the Direct-to-Core proxy values for the SSR wrapped fetch endowment
*/
getCoreProxy(appCoreProxy?: DirectToCoreProxy, proxyForSSR?: boolean): DirectToCoreProxy | undefined;
}
export interface MiddlewareResponse {
hasHeader(name: string): boolean;
set(header: any): void;
setHeader(name: string, value: string | string[]): void;
setSiteGenerationMetadata(metadata: any): void;
status(status: number): MiddlewareResponse;
send(object: any): void;
sendStatus(httpCode: number): void;
stream(stream: Readable): void;
type(type: string): MiddlewareResponse;
cookie(name: string, value?: string, options?: any): MiddlewareResponse;
}
//# sourceMappingURL=server.d.ts.map