X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=ui%2Fweb%2Fstart.js;h=46a8bb75884f67da0c4b2ecfc9138bff44fb7ab2;hb=05558d929eb51343f080455aae1a4ec4fed62fa5;hp=9b18156cffee67d340d172bfac4753c40fd9f3a6;hpb=a0616ba11b5cdeee412ccfd4f75ad2ba25f25bf1;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/start.js b/ui/web/start.js index 9b18156c..46a8bb75 100644 --- a/ui/web/start.js +++ b/ui/web/start.js @@ -1,17 +1,17 @@ -const http = require('node:http'), - path = require('node:path'), - { env } = require('node:process'), - finalhandler = require('finalhandler'), - 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' -const isCFEnvironment = env.VCAP_APPLICATION !== undefined, - PORT = isCFEnvironment ? parseInt(env.PORT) : 3030, - uiPath = path.join(__dirname, './dist'); +import finalhandler from 'finalhandler' +import serveStatic from 'serve-static' -const serve = serveStatic(uiPath); +const isCFEnvironment = env.VCAP_APPLICATION != null +const PORT = isCFEnvironment ? parseInt(env.PORT) : 3030 +const uiPath = join(dirname(fileURLToPath(import.meta.url)), './dist') -const server = http.createServer(function onRequest(req, res) { - serve(req, res, finalhandler(req, res)); -}); +const serve = serveStatic(uiPath) -server.listen(PORT, () => console.info(`App running at: http://localhost:${PORT}`)); +const server = createServer((req, res) => serve(req, res, finalhandler(req, res))) + +server.listen(PORT, () => console.info(`Web UI running at: http://localhost:${PORT}`))