API › @builder.io/qwik-city/middleware/node

createQwikCity

export declare function createQwikCity(opts: QwikCityNodeRequestOptions): {
  router: (
    req: IncomingMessage | Http2ServerRequest,
    res: ServerResponse,
    next: NodeRequestNextFunction,
  ) => Promise<void>;
  notFound: (
    req: IncomingMessage | Http2ServerRequest,
    res: ServerResponse,
    next: (e: any) => void,
  ) => Promise<void>;
  staticFile: (
    req: IncomingMessage | Http2ServerRequest,
    res: ServerResponse,
    next: (e?: any) => void,
  ) => Promise<void>;
};

参数

类型

描述

opts

QwikCityNodeRequestOptions

{ router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>; notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e: any) => void) => Promise<void>; staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>; }

编辑此部分

NodeRequestNextFunction

export interface NodeRequestNextFunction

编辑此部分

PlatformNode

export interface PlatformNode

属性

修饰符

类型

描述

incomingMessage?

IncomingMessage | Http2ServerRequest

(可选)

node?

string

(可选)

ssr?

true

(可选)

编辑此部分

QwikCityNodeRequestOptions

export interface QwikCityNodeRequestOptions extends ServerRenderOptions

扩展: ServerRenderOptions

属性

修饰符

类型

描述

getClientConn?

(req: IncomingMessage | Http2ServerRequest) => ClientConn

(可选) 提供一个函数,该函数返回给定请求的 ClientConn

getOrigin?

(req: IncomingMessage | Http2ServerRequest) => string | null

(可选) 提供一个函数,该函数计算服务器的来源,用于解析相对 URL 并根据 CSRF 攻击验证请求来源。

如果未指定,则默认为 ORIGIN 环境变量(如果已设置)。

如果未设置 ORIGIN,则它将从传入的请求中推断出来,这对于生产环境来说是不推荐的。您可以分别将 PROTOCOL_HEADERHOST_HEADER 指定为 X-Forwarded-ProtoX-Forwarded-Host 来覆盖默认行为。

origin?

string

(可选)

static?

{ root?: string; cacheControl?: string; }

(可选) 用于提供静态文件的选项

编辑此部分