diff --git a/README.md b/README.md index 5abc647..b45e588 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,15 @@ bee-dashboard This should open the webpage on [`http://localhost:8080`](http://localhost:8080) +You can also define your own port with the `PORT` environment variable. E.g. + +```sh +export PORT=3005 +bee-dashboard +``` + +Will start the bee-dashboard on [`http://localhost:3005`](http://localhost:3005) + ### Docker To build Docker image and run it, execute the following from inside project directory: diff --git a/serve.js b/serve.js index aa798c3..5085e43 100755 --- a/serve.js +++ b/serve.js @@ -1,34 +1,35 @@ #!/usr/bin/env node const path = require('path') -const handler = require('serve-handler'); -const http = require('http'); +const handler = require('serve-handler') +const http = require('http') const opener = require('opener') +const port = process.env.PORT || 8080 + const serverConfig = { public: path.join(__dirname, 'build'), trailingSlash: false, - rewrites: [ - { source: "**", destination: "/index.html" }, - ], + rewrites: [{ source: '**', destination: '/index.html' }], headers: [ - { - source: "*", - headers: [{ - key: "Cache-Control", - value: "max-age=3600" - }] - } - ] + { + source: '*', + headers: [ + { + key: 'Cache-Control', + value: 'max-age=3600', + }, + ], + }, + ], } const server = http.createServer((request, response) => { + return handler(request, response, serverConfig) +}) - return handler(request, response, serverConfig); -}) - -server.listen(8080, () => { - console.log('Starting up Bee Dashboard on address http://localhost:8080') +server.listen(port, () => { + console.log(`Starting up Bee Dashboard on address http://localhost:${port}`) console.log('Hit CTRL-C to stop the server') - opener('http://localhost:8080') + opener(`http://localhost:${port}`) })