-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirmware-server.js
More file actions
64 lines (52 loc) · 1.59 KB
/
firmware-server.js
File metadata and controls
64 lines (52 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const path = require('path');
const express = require("express");
const fs = require('fs');
const app = express();
const port = 6060;
const home = process.env.HOME;
const local = path.join(home, "fieldkit/dev-env/archive/local");
const archived = "archive/fk-firmware-266";
const serving = local;
function applicationFirmware(req, res) {
const name = "fk-bundled-fkb.bin";
fs.realpath(path.join(serving, name), (err, real) => {
if (err) {
console.log('error', err);
return;
}
console.log(req.connection.remoteAddress, real, req.params);
res.sendFile(real);
});
}
function bootloaderFirmware(req, res) {
const name = "fkbl-fkb.bin";
fs.realpath(path.join(serving, name), (err, real) => {
if (err) {
console.log('error', err);
return;
}
console.log(req.connection.remoteAddress, real, req.params);
res.sendFile(real);
});
}
app.get("/:deviceId/fk-bundled-fkb.bin", applicationFirmware);
app.get("/:deviceId/fkbl-fkb.bin", bootloaderFirmware);
app.get("/fk-bundled-fkb.bin", applicationFirmware);
app.get("/fkbl-fkb.bin", bootloaderFirmware);
app.post("/upload", (req, res) => {
let received = 0;
req.on('data', (chunk) => {
received += chunk.length;
});
req.on('end', () => {
console.log('received', received, 'bytes');
})
res.status(200).send("ok");
});
app.get("*", (req, res, n) => {
res.status(404).send("404 not found");
});
app.listen(port, () => {
console.log("Listening on :" + port);
console.log("Serving", serving)
});