Skip to content

Commit

Permalink
Replace the node-static package with serve-handler (#9)
Browse files Browse the repository at this point in the history
It appears that node-static module hasn't been updated for 6 years and
it has some vulnerabilities. On the other and serve-handler is the core
package of `serve`, which is maintained by vercel. So it looks like it's
a safer option. There were more options to choose from, but that looks
like a good option, and required less effort to migrate.
  • Loading branch information
canova authored Dec 11, 2024
1 parent cfdac13 commit ae2ec44
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 54 deletions.
138 changes: 89 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"dependencies": {
"crc-full": "^1.1.0",
"node-hid": "^3.0.0",
"node-static": "^0.7.11",
"serialport": "^12.0.0",
"serve-handler": "^6.1.6",
"usb": "^2.9.0"
}
}
7 changes: 3 additions & 4 deletions usb-power-profiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const url = require('url');
const { createDecipheriv } = require('node:crypto');
const { SerialPort } = require('serialport');
const { CRC } = require('crc-full');
const nStatic = require('node-static');
const serveHandler = require('serve-handler');

const CHARGER_LAB_VENDOR_ID = 0x5FC9;
const FNIRSI_VENDOR_ID = 0x2E3C;
Expand Down Expand Up @@ -1435,19 +1435,18 @@ const app = (req, res) => {
}

if (req.url == "/" || req.url == "/index.html") {
fileServer.serveFile('/index.html', 200, {}, req, res);
serveHandler(req, res, { public: '.' });
}
};

var server, fileServer;
var server;

async function runPowerCollectionServer(customPort) {
const port = customPort || process.env.PORT || 2121;
server = http.createServer(app)
server.listen(port, "0.0.0.0", () => {
console.log(`Ensure devtools.performance.recording.power.external-url is set to http://localhost:${port}/power in 'about:config'.`);
});
fileServer = new nStatic.Server();
}

if (require.main === module) {
Expand Down

0 comments on commit ae2ec44

Please sign in to comment.