@ui5/server
Methods
(static) serve(graph, options, error, graphFactoryopt, projectWatcheropt) → {Promise<module:@ui5/server~ServerInstance>}
Description: Start a server for the given project (sub-)tree.
Source: server/lib/server.js, line 102
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
graph | @ui5/project/graph/ProjectGraph | Project graph | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options | object | Options Properties:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
error | function | Error callback. Will be called when an error occurs outside of request handling. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
graphFactory | function | optional | Async factory that re-resolves the project graph with the same parameters used to build the initial graph. When provided,the returned reinitialize re-creates the serving stack on aproject-definition change. Omitted, reinitialize is a no-op. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
projectWatcher | object | optional | Injected @ui5/project/internal/graph/ProjectDefinitionWatchermodule namespace. The server operates on the project graph as an opaque interface and does not depend on @ui5/project, so the owner (the UI5 CLI) threads this in to provide the live re-resolution capability. Required alongside graphFactory; omit both for a static serve. |
Returns:
Promise resolving once the server is listening
Type: Promise<module:@ui5/server~ServerInstance>
(static) serveMiddleware(graph, optionsopt, erroropt) → {Promise<object>}
Description: Assembles the UI5 middleware for a project graph and returns it as a single connect/Express middleware, for mounting into an existing HTTP server rather than starting one.
Unlike module:@ui5/server.serve, this does not bind a port, attach the live-reload WebSocket server, or install the terminal HTML error handler; those belong to the server the UI5 CLI owns. The caller mounts the returned middleware on its own express() app or Express Router/Connect app via app.use(middleware) and owns error handling and the HTTP listener.
close must be called on teardown to release the BuildServer's source watcher and build-cache handle.
Note: A project graph can be served only once. Do not call both serveMiddleware and module:@ui5/server.serve for the same graph.
Source: server/lib/serveMiddleware.js, line 58
Example:
import express from "express";
import {serveMiddleware} from "@ui5/server";
const app = express();
const {middleware, close} = await serveMiddleware(graph);
app.use(middleware);
const listener = app.listen(8080);
// On teardown, release the BuildServer's watcher and build-cache handle.
listener.close();
await close();Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
graph | @ui5/project/graph/ProjectGraph | Project graph | |||||||||||||||||||||||||||||||||||||||||
options | object | optional | Options Properties:
| ||||||||||||||||||||||||||||||||||||||||
error | function | optional | Error callback. Will be called when the BuildServer emits an error outside of request handling. |
Returns:
Promise resolving with an object containing the middleware (a connect/Express-compatible handler to be mounted via app.use()) and a close function releasing the BuildServer's watcher and cache.
Type: Promise<object>
Type Definitions
SAPTargetCSPOptions
Description: SAP target CSP middleware options
Source: server/lib/server.js, line 11
Properties:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
defaultPolicy | string | optional | "sap-target-level-1" | |
defaultPolicyIsReportOnly | string | optional | true | |
defaultPolicy2 | string | optional | "sap-target-level-3" | |
defaultPolicy2IsReportOnly | string | optional | true | |
ignorePaths | Array<string> | optional | ["test-resources/sap/ui/qunit/testrunner.html"] |
SAP target CSP middleware options
Type:
- object
ServerInstance
Description: Handle of a running server instance.
Source: server/lib/server.js, line 40
Properties:
| Name | Type | Description |
|---|---|---|
port | number | Port the server is listening on |
https | boolean | Whether HTTPS is used |
close | module:@ui5/server~closeServer | Stops the server |
reinitialize | function | Re-creates the serving stack. Returns a Promisethat resolves once the new stack is in place. A no-op when no graphFactory was provided to module:@ui5/server.serve. |
Handle of a running server instance.
Type:
- object
closeServer(callbackopt) → {Promise<void>|undefined}
Description: Stops a running server.
Can be awaited or used with a callback. Called without arguments, it returns a Promise that resolves once teardown completes and rejects if teardown threw. Called with a callback, it returns undefined and invokes the callback once teardown completes, with no arguments on success or with the error as its first argument if teardown threw.
Source: server/lib/server.js, line 23
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
callback | function | optional | Invoked once teardown completes. Receives the teardown error as its first argument if teardown threw, otherwise no arguments. |
Returns:
A Promise that resolves once teardown completes when called without a callback, otherwise undefined.
Type: Promise<void> | undefined

