interface ApiSettingsSchemaOpenApi {
    assets?: AssetsConfig;
    cors?: CorsOptions;
    etag?: boolean | "weak" | "strong" | ETagFunction;
    http2?: boolean;
    httpServerTimeout?: number;
    internalServiceSpecialChar?: string | RegExp;
    ip?: string;
    log4XXResponses?: boolean;
    logRequest?: null | LogLevels;
    logRequestParams?: null | LogLevels;
    logResponse?: null | LogLevels;
    logResponseData?: null | LogLevels;
    logRouteRegistration?: null | LogLevels;
    onError?: ((req, res, error) => void);
    openapi?: ApiSettingsOpenApi;
    optimizeOrder?: boolean;
    path?: string;
    port?: number;
    qsOptions?: IParseOptions;
    rateLimit?: RateLimitSettings;
    rootCallOptions?: CallingOptions;
    routes?: ApiRouteSchema[];
    server?: APISettingServer;
    use?: (routeMiddleware | routeMiddlewareError)[];
}

Hierarchy

  • ApiSettingsSchema
    • ApiSettingsSchemaOpenApi

Properties

assets?: AssetsConfig

It serves assets with the serve-static module like ExpressJS.

cors?: CorsOptions

Cross-origin resource sharing configuration (using module cors)

Example

{
// Configures the Access-Control-Allow-Origin CORS header.
origin: "*", // ["http://localhost:3000", "https://localhost:4000"],
// Configures the Access-Control-Allow-Methods CORS header.
methods: ["GET", "OPTIONS", "POST", "PUT", "DELETE"],
// Configures the Access-Control-Allow-Headers CORS header.
allowedHeaders: [],
// Configures the Access-Control-Expose-Headers CORS header.
exposedHeaders: [],
// Configures the Access-Control-Allow-Credentials CORS header.
credentials: false,
// Configures the Access-Control-Max-Age CORS header.
maxAge: 3600
}

See

https://moleculer.services/docs/0.14/moleculer-web.html#CORS-headers

etag?: boolean | "weak" | "strong" | ETagFunction

The etag option value can be false, true, weak, strong, or a custom Function

http2?: boolean

Use HTTP2 server (experimental)

Default

false
httpServerTimeout?: number

HTTP Server Timeout

Default

null
internalServiceSpecialChar?: string | RegExp

Special char for internal services
Note: RegExp type is not official

Default

"~"

Example

"~" => /~node/~action => /$node/~action

Example

/[0-9]+/g => /01234demo/hello2021 => /demo/hello `(not official)`
ip?: string

Exposed IP

Default

process.env.IP || "0.0.0.0"
log4XXResponses?: boolean

If set to true, it will log 4xx client errors, as well

Default

false
logRequest?: null | LogLevels

Log each request (default to "info" level)

Default

"info"
logRequestParams?: null | LogLevels

Log the request ctx.params (default to "debug" level)

Default

"debug"
logResponse?: null | LogLevels

Log each response (default to "info" level)

Default

"info"
logResponseData?: null | LogLevels

Log the response data (default to disable)

Default

null
logRouteRegistration?: null | LogLevels

Log the route registration/aliases related activity

Default

"info"
onError?: ((req, res, error) => void)

You can add route-level & global-level custom error handlers.
In handlers, you must call the res.end. Otherwise, the request is unhandled.

Type declaration

    • (req, res, error): void
    • Parameters

      • req: IncomingMessage
      • res: ServerResponse<IncomingMessage>
      • error: Error

      Returns void

optimizeOrder?: boolean

Optimize route order

Default

true
path?: string

Global path prefix

port?: number

Exposed port

Default

process.env.PORT || 3000
qsOptions?: IParseOptions

Options passed on to qs

rateLimit?: RateLimitSettings

The Moleculer-Web has a built-in rate limiter with a memory store.

rootCallOptions?: CallingOptions

CallOption for the root action api.rest

Default

null
routes?: ApiRouteSchema[]
server?: APISettingServer

Used server instance. If null, it will create a new HTTP(s)(2) server
If false, it will start without server in middleware mode

Default

true
use?: (routeMiddleware | routeMiddlewareError)[]

It supports Connect-like middlewares in global-level, route-level & alias-level.
Signature: function (req, res, next) {...}.
Signature: function (err, req, res, next) {...}.
For more info check express middleware