docs: ui/web/README.md: fix link
[e-mobility-charging-stations-simulator.git] / ui / web / start.js
index c73a2b320413c008b9d29a3bae392a7d683ca201..39cdf0f446d338a700f2f22763ff2193b3d2187f 100644 (file)
@@ -1,15 +1,17 @@
-const finalhandler = require('finalhandler'),
-  http = require('http'),
-  path = require('path'),
-  serveStatic = require('serve-static');
+import { createServer } from 'node:http';
+import { dirname, join } from 'node:path';
+import { env } from 'node:process';
+import { fileURLToPath } from 'node:url';
+import finalhandler from 'finalhandler';
+import serveStatic from 'serve-static';
 
-const isCFEnvironment = process.env.VCAP_APPLICATION !== undefined,
-  PORT = isCFEnvironment ? parseInt(process.env.PORT) : 3030,
-  uiPath = path.join(__dirname, './dist');
+const isCFEnvironment = env.VCAP_APPLICATION !== undefined,
+  PORT = isCFEnvironment ? parseInt(env.PORT) : 3030,
+  uiPath = join(dirname(fileURLToPath(import.meta.url)), './dist');
 
 const serve = serveStatic(uiPath);
 
-const server = http.createServer(function onRequest(req, res) {
+const server = createServer(function onRequest(req, res) {
   serve(req, res, finalhandler(req, res));
 });