I am trying to create a standard SAP CAP (Cloud Platform Application Model) in SAP Business Application Studio and also extending it with additional Express endpoints besides the ones served by CDS services. I have the following project structure:
Content of package.json:
{
"name": "<app-name>",
"version": "1.0.0",
"description": "A simple CAP project.",
"repository": "<Add your repository here>",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@sap/cds": "^3",
"@sap/cds-dk": "^1.8.5",
"@sap/hana-client": "^2.4.177",
"express": "^4",
"multer": "^1.4.2"
},
"scripts": {
"start": "npx cds run"
},
"cds": {
"hana": {
"deploy-format": "hdbtable"
},
"requires": {
"db": {
"kind": "sql"
}
}
},
"devDependencies": {
"sqlite3": "^4.2.0"
}}
Server.js:
module.exports = async() => {
const express = require('express')
const cds = require('@sap/cds')
const app = express()
const port = process.env.port || 4004
app.use('/', express.static('app/'))
app.get('/', (req, res) => res.redirect("/app/index.html"))
cds.connect("db")
.serve("all")
.in(app)
return app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))}
When I run cds watch command the application properly starts, however when I open the Fiori Elements application the following error message appears:
If I remove the server.js file from the srv folder, the application works perfectly. What could cause the error message? Is there any additional configuration required?