Web UI: Fix CF environment detection
[e-mobility-charging-stations-simulator.git] / src / ui / web / start.js
index e804fc11484b6cf2c7a36f604bd070fa69b7f6c5..ed6e3e01ff65c0f81696ba9805a5b622f8c5169c 100644 (file)
@@ -3,8 +3,9 @@ const path = require('path'),
   http = require('http'),
   serveStatic = require('serve-static');
 
-const PORT = process.env.PORT || 3030,
-  uiPath = path.join(__dirname, './dist/');
+const isCFEnvironment = process.env.VCAP_APPLICATION !== undefined,
+  PORT = isCFEnvironment ? parseInt(process.env.PORT) : 3030,
+  uiPath = path.join(__dirname, './dist');
 
 const serve = serveStatic(uiPath);
 
@@ -12,4 +13,4 @@ const server = http.createServer(function onRequest(req, res) {
   serve(req, res, finalhandler(req, res));
 });
 
-server.listen(PORT, () => console.info(`http://localhost:${PORT}`));
+server.listen(PORT, () => console.info(`App running at: http://localhost:${PORT}`));