support custom port for web and api via cli args
This commit is contained in:
@ -129,6 +129,8 @@ node src/index.js
|
||||
# Server running at http://127.0.0.1:8080
|
||||
```
|
||||
|
||||
> Note: You can also use a custom port with `--port 8123`
|
||||
|
||||
## Upgrading
|
||||
|
||||
Run the following commands from inside the `meshtastic-map` repo.
|
||||
|
40
src/index.js
40
src/index.js
@ -1,6 +1,8 @@
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
const protobufjs = require("protobufjs");
|
||||
const commandLineArgs = require("command-line-args");
|
||||
const commandLineUsage = require("command-line-usage");
|
||||
|
||||
// create prisma db client
|
||||
const { PrismaClient } = require("@prisma/client");
|
||||
@ -11,6 +13,42 @@ BigInt.prototype.toJSON = function() {
|
||||
return this.toString();
|
||||
}
|
||||
|
||||
const optionsList = [
|
||||
{
|
||||
name: 'help',
|
||||
alias: 'h',
|
||||
type: Boolean,
|
||||
description: 'Display this usage guide.'
|
||||
},
|
||||
{
|
||||
name: "port",
|
||||
type: Number,
|
||||
description: "Port to serve web ui and api from.",
|
||||
},
|
||||
];
|
||||
|
||||
// parse command line args
|
||||
const options = commandLineArgs(optionsList);
|
||||
|
||||
// show help
|
||||
if(options.help){
|
||||
const usage = commandLineUsage([
|
||||
{
|
||||
header: 'Meshtastic Map',
|
||||
content: 'A map of all Meshtastic nodes heard via MQTT.',
|
||||
},
|
||||
{
|
||||
header: 'Options',
|
||||
optionList: optionsList,
|
||||
},
|
||||
]);
|
||||
console.log(usage);
|
||||
return;
|
||||
}
|
||||
|
||||
// get options and fallback to default values
|
||||
const port = options["port"] ?? 8080;
|
||||
|
||||
// load protobufs
|
||||
const root = new protobufjs.Root();
|
||||
root.resolvePath = (origin, target) => path.join(__dirname, "protos", target);
|
||||
@ -377,7 +415,7 @@ app.get('/api/v1/waypoints', async (req, res) => {
|
||||
});
|
||||
|
||||
// start express server
|
||||
const listener = app.listen(8080, () => {
|
||||
const listener = app.listen(port, () => {
|
||||
const port = listener.address().port;
|
||||
console.log(`Server running at http://127.0.0.1:${port}`);
|
||||
});
|
||||
|
Reference in New Issue
Block a user