Skip to content

@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:
NameTypeAttributesDescription
graph@ui5/project/graph/ProjectGraphProject graph
optionsobjectOptions
Properties:
NameTypeAttributesDefaultDescription
portnumberPort to listen to
changePortIfInUsebooleanoptionalfalseIf true, change the port if it is already in use
httpsbooleanoptionalfalseWhether HTTPS should be used - defaults to http
keystringoptionalPath to private key to be used for https
certstringoptionalPath to certificate to be used for for https
simpleIndexbooleanoptionalfalseUse a simplified view for the server directory listing
liveReloadbooleanoptionalfalseAutomatically reload connected browsers when project sources change
acceptRemoteConnectionsbooleanoptionalfalseIf true, listens to remote connections and
not only to localhost connections
sendSAPTargetCSPboolean | module:@ui5/server.SAPTargetCSPOptionsoptionalfalseIf set to true or an object, then the default (or configured)
set of security policies that SAP and UI5 aim for (AKA 'target policies'),
are send for any requested *.html file
serveCSPReportsbooleanoptionalfalseEnable CSP reports serving for request url
'/.ui5/csp/csp-reports.json'
cachestringoptional"Default"Cache mode to use for building UI5 projects.
ui5DataDirstringoptionalExplicit UI5 data directory to use for the build cache.
Overrides the UI5_DATA_DIR environment variable,
the UI5 configuration file, and the default of ~/.ui5.
includedTasksArray<string>optionalA list of tasks to be added to the default execution set.
Takes precedence over excludedTasks.
excludedTasksArray<string>optionalA list of tasks to be excluded from the default task
execution set.
rootConfigPathstringoptionalCustom config path for the root project (from --config),
threaded to the definition watcher so it watches the right file.
workspaceConfigPathstringoptionalWorkspace config path (default ui5-workspace.yaml);
threaded to the definition watcher. Omit in static-graph mode.
dependencyDefinitionPathstringoptionalStatic dependency-definition file
(from --dependency-definition); watched when present.
cwdstringoptionalBase directory for resolving the watcher's relative paths.
errorfunctionError callback. Will be called when an error occurs outside of request handling.
graphFactoryfunctionoptionalAsync 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 a
project-definition change. Omitted, reinitialize is a no-op.
projectWatcherobjectoptionalInjected @ui5/project/internal/graph/ProjectDefinitionWatcher
module 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:
NameTypeAttributesDescription
graph@ui5/project/graph/ProjectGraphProject graph
optionsobjectoptionalOptions
Properties:
NameTypeAttributesDefaultDescription
sendSAPTargetCSPboolean | module:@ui5/server.SAPTargetCSPOptionsoptionalfalseIf set to true or an object, then the default (or configured)
set of security policies that SAP and UI5 aim for (AKA 'target policies'),
are send for any requested *.html file
serveCSPReportsbooleanoptionalfalseEnable CSP reports serving for request url
'/.ui5/csp/csp-reports.json'
simpleIndexbooleanoptionalfalseUse a simplified view for the server directory listing
cachestringoptional"Default"Cache mode to use for building UI5 projects.
ui5DataDirstringoptionalExplicit UI5 data directory to use for the build cache.
Overrides the UI5_DATA_DIR environment variable,
the UI5 configuration file, and the default of ~/.ui5.
includedTasksArray<string>optionalA list of tasks to be added to the default execution set.
Takes precedence over excludedTasks.
excludedTasksArray<string>optionalA list of tasks to be excluded from the default task
execution set.
errorfunctionoptionalError 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:
NameTypeAttributesDefaultDescription
defaultPolicystringoptional"sap-target-level-1"
defaultPolicyIsReportOnlystringoptionaltrue
defaultPolicy2stringoptional"sap-target-level-3"
defaultPolicy2IsReportOnlystringoptionaltrue
ignorePathsArray<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:
NameTypeDescription
portnumberPort the server is listening on
httpsbooleanWhether HTTPS is used
closemodule:@ui5/server~closeServerStops the server
reinitializefunctionRe-creates the serving stack. Returns a Promise
that 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:
NameTypeAttributesDescription
callbackfunctionoptionalInvoked 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