From 28402c58b30801b98e738c6bba55848612272059 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 17 Feb 2021 12:28:27 +0100 Subject: [PATCH] Simplified redirects to imported apps --- fiori/app/bookshop.html | 2 +- fiori/app/reviews.html | 2 +- fiori/server.js | 21 ++++++++++----------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/fiori/app/bookshop.html b/fiori/app/bookshop.html index 13c22ac5..e7c07e25 100644 --- a/fiori/app/bookshop.html +++ b/fiori/app/bookshop.html @@ -1,3 +1,3 @@ - + diff --git a/fiori/app/reviews.html b/fiori/app/reviews.html index a74f6c74..75af8860 100644 --- a/fiori/app/reviews.html +++ b/fiori/app/reviews.html @@ -1,3 +1,3 @@ - + diff --git a/fiori/server.js b/fiori/server.js index 887190f9..a8dc4298 100644 --- a/fiori/server.js +++ b/fiori/server.js @@ -1,19 +1,18 @@ -const express = require ('express') const cds = require ('@sap/cds') cds.once('bootstrap',(app)=>{ - const {dirname} = require ('path') - // serving the orders app imported from @capire/orders - const orders_app = dirname (require.resolve('@capire/orders/app/orders/webapp/manifest.json')) - app.use ('/orders/webapp', express.static(orders_app)) - // serving the vue.js app imported from @capire/bookshop - const bookshop_app = dirname (require.resolve('@capire/bookshop/app/vue/index.html')) - app.use ('/vue/bookshop', express.static(bookshop_app)) - // serving the vue.js app imported from @capire/reviews - const reviews_app = dirname (require.resolve('@capire/reviews/app/vue/index.html')) - app.use ('/vue/reviews', express.static(reviews_app)) + app.use ('/orders/webapp', _from('@capire/orders/app/orders/webapp/manifest.json')) + app.use ('/bookshop', _from('@capire/bookshop/app/vue/index.html')) + app.use ('/reviews', _from('@capire/reviews/app/vue/index.html')) }) cds.once('served', require('./srv/mashup')) module.exports = cds.server + + +// ----------------------------------------------------------------------- +// Helper for serving static content from npm-installed packages +const {static} = require('express') +const {dirname} = require('path') +const _from = target => static (dirname (require.resolve(target)))