@@ -58,6 +58,73 @@ export class HelloWorldApp extends RestApplication {
5858
5959## Configuration
6060
61+ The REST server can be configured by passing a ` rest ` property inside your
62+ RestApplication options. For example, the following code customizes the port
63+ number that a REST server listens on.
64+
65+ ``` ts
66+ const app = new RestApplication ({
67+ rest: {
68+ port: 3001 ,
69+ },
70+ });
71+ ```
72+
73+ ### Customize How OpenAPI Spec is Served
74+
75+ There are a few options under ` rest.openApiSpec ` to configure how OpenAPI spec
76+ is served by the given REST server.
77+
78+ - servers: Configure servers for OpenAPI spec
79+ - setServersFromRequest: Set ` servers ` based on HTTP request headers, default to
80+ ` false `
81+ - endpointMapping: Maps urls for various forms of the spec. Default to:
82+
83+ ``` js
84+ {
85+ ' /openapi.json' : {version: ' 3.0.0' , format: ' json' },
86+ ' /openapi.yaml' : {version: ' 3.0.0' , format: ' yaml' },
87+ }
88+ ```
89+
90+ ``` ts
91+ const app = new RestApplication ({
92+ rest: {
93+ openApiSpec: {
94+ servers: [{url: ' http://127.0.0.1:8080' }],
95+ setServersFromRequest: false ,
96+ endpointMapping: {
97+ ' /openapi.json' : {version: ' 3.0.0' , format: ' json' },
98+ ' /openapi.yaml' : {version: ' 3.0.0' , format: ' yaml' },
99+ },
100+ },
101+ },
102+ });
103+ ```
104+
105+ ### Configure the API Explorer
106+
107+ LoopBack allows externally hosted API Explorer UI to render the OpenAPI
108+ endpoints for a REST server. Such URLs can be specified with ` rest.apiExplorer ` :
109+
110+ - url: URL for the hosted API Explorer UI, default to
111+ ` https://loopback.io/api-explorer ` .
112+ - httpUrl: URL for the API explorer served over plain http to deal with mixed
113+ content security imposed by browsers as the spec is exposed over ` http ` by
114+ default. See https://github.com/strongloop/loopback-next/issues/1603 . Default
115+ to the value of ` url ` .
116+
117+ ``` ts
118+ const app = new RestApplication ({
119+ rest: {
120+ apiExplorer: {
121+ url: ' https://petstore.swagger.io' ,
122+ httpUrl: ' http://petstore.swagger.io' ,
123+ },
124+ },
125+ });
126+ ```
127+
61128### Enable HTTPS
62129
63130Enabling HTTPS for the LoopBack REST server is just a matter of specifying the
@@ -89,7 +156,19 @@ export async function main() {
89156}
90157```
91158
92- ### Add servers to application instance
159+ ### ` rest ` options
160+
161+ | Property | Type | Purpose |
162+ | ----------- | ------------------- | --------------------------------------------------------------------------------------------------------- |
163+ | port | number | Specify the port on which the RestServer will listen for traffic. |
164+ | protocol | string (http/https) | Specify the protocol on which the RestServer will listen for traffic. |
165+ | key | string | Specify the SSL private key for https. |
166+ | cert | string | Specify the SSL certificate for https. |
167+ | sequence | SequenceHandler | Use a custom SequenceHandler to change the behavior of the RestServer for the request-response lifecycle. |
168+ | openApiSpec | OpenApiSpecOptions | Customize how OpenAPI spec is served |
169+ | apiExplorer | ApiExplorerOptions | Customize how API explorer is served |
170+
171+ ## Add servers to application instance
93172
94173You can add server instances to your application via the ` app.server() ` method
95174individually or as an array using ` app.servers() ` method. Using ` app.server() `
0 commit comments