Improved and documented server.js
This commit is contained in:
@@ -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')
|
const cds = require ('@sap/cds')
|
||||||
|
|
||||||
// Mashup services after bootstrapping...
|
// Mashup services after all are served...
|
||||||
cds.on('listening', async()=>{
|
cds.once('served', async()=>{
|
||||||
|
|
||||||
// react on event messages from reviews service
|
// react on event messages from reviews service
|
||||||
const ReviewsService = await cds.connect.to ('ReviewsService')
|
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
|
// Delegate bootstrapping to built-in server.js
|
||||||
module.exports = cds.server
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user