diff --git a/incubator/nodejs-express/image/project/package.json b/incubator/nodejs-express/image/project/package.json index 759088556..a4dfb62f6 100644 --- a/incubator/nodejs-express/image/project/package.json +++ b/incubator/nodejs-express/image/project/package.json @@ -16,6 +16,7 @@ "dependencies": { "@cloudnative/health-connect": "^2.0.0", "appmetrics-prometheus": "^2.0.0", + "vhost": "^3.0.2", "express": "~4.16.0" }, "devDependencies": { diff --git a/incubator/nodejs-express/image/project/server.js b/incubator/nodejs-express/image/project/server.js index 1c76a7305..8a1e16d0f 100644 --- a/incubator/nodejs-express/image/project/server.js +++ b/incubator/nodejs-express/image/project/server.js @@ -1,4 +1,5 @@ const express = require('express'); +const vhost = require('vhost'); const health = require('@cloudnative/health-connect'); const fs = require('fs'); @@ -18,13 +19,14 @@ function getEntryPoint() { return package.main; } -require(basePath + getEntryPoint())(app); - const healthcheck = new health.HealthChecker(); app.use('/live', health.LivenessEndpoint(healthcheck)); app.use('/ready', health.ReadinessEndpoint(healthcheck)); app.use('/health', health.HealthEndpoint(healthcheck)); +const userApp = require(basePath + getEntryPoint()).app; +app.use(vhost('*', userApp)); + app.get('*', (req, res) => { res.status(404).send("Not Found"); }); diff --git a/incubator/nodejs-express/templates/simple/app.js b/incubator/nodejs-express/templates/simple/app.js index 18c28ca88..76206249c 100644 --- a/incubator/nodejs-express/templates/simple/app.js +++ b/incubator/nodejs-express/templates/simple/app.js @@ -1,7 +1,7 @@ -module.exports = (app) => { +const app = require('express')() - app.get('/', (req, res) => { - res.send("Hello World!"); - }); - -} +app.get('/', (req, res) => { + res.send("Hello World!"); +}); + +module.exports.app = app; diff --git a/incubator/nodejs-express/templates/skaffold/app.js b/incubator/nodejs-express/templates/skaffold/app.js index 4da778208..23afcd220 100644 --- a/incubator/nodejs-express/templates/skaffold/app.js +++ b/incubator/nodejs-express/templates/skaffold/app.js @@ -1,9 +1,9 @@ -module.exports = (app) => { +const app = require('express')() - app.set('views', __dirname + "/views"); - app.set('view engine', 'pug'); +app.set('views', __dirname + "/views"); +app.set('view engine', 'pug'); - app.use('/', require('./routes')); - -} +app.use('/', require('./routes')); + +module.exports.app = app; \ No newline at end of file