-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (37 loc) · 1.25 KB
/
index.js
File metadata and controls
47 lines (37 loc) · 1.25 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
"use strict";
const fs = require("fs");
const express = require("express");
const path = require("path");
const app = express();
// app.use(require('morgan')('dev'));
app.use("/updates/releases", express.static(path.join(__dirname, "releases")));
app.get("/updates/:productName/latest", (req, res) => {
const productName = req.param("productName");
const latest = getLatestRelease(productName);
const clientVersion = req.query.v;
if (clientVersion === latest) {
res.status(204).end();
} else {
res.json({
url: `${getBaseUrl()}/updates/releases/${productName}/darwin/${latest}/${productName}.zip`
});
}
});
let getLatestRelease = (productName) => {
const dir = `${__dirname}/releases/${productName}/darwin`;
const versionsDesc = fs.readdirSync(dir).filter((file) => {
const filePath = path.join(dir, file);
return fs.statSync(filePath).isDirectory();
}).reverse();
return versionsDesc[0];
};
let getBaseUrl = () => {
if (process.env.NODE_ENV === "development") {
return "http://localhost:3000";
} else {
return "http://thingsSDK.com";
}
};
app.listen(process.env.PORT, () => {
console.log(`Express server listening on port ${process.env.PORT}`);
});