Improved and documented server.js

This commit is contained in:
Daniel
2020-04-12 06:12:26 +02:00
parent cf3c45466a
commit 93f4cd5c6e

View File

@@ -1,7 +1,13 @@
////////////////////////////////////////////////////////////////////////////
//
// This is an example of using a project-local server.js to intercept
// the default bootstrapping process.
//
const cds = require ('@sap/cds')
// Mashup services after bootstrapping...
cds.on('listening', async()=>{
// Mashup services after all are served...
cds.once('served', async()=>{
// react on event messages from reviews service
const ReviewsService = await cds.connect.to ('ReviewsService')
@@ -26,5 +32,19 @@ cds.on('listening', async()=>{
})
// Other bootstrapping events you could hook in to...
/* eslint-disable no-unused-vars */
cds.on('loaded', (model) => {/* ... */})
cds.on('serving', (srv) => {/* ... */})
cds.on('connect', (srv) => {/* ... */})
cds.once('listening', ({server,url}) => {/* ... */})
// Delegate bootstrapping to built-in server.js
module.exports = cds.server
// Monkey patching older releases
if (cds.version < '3.33.4') cds.once('listening', ()=> cds.emit('served'))
// Launch server if started directly from command-line
if (!module.parent) cds.server()