-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (33 loc) · 1.01 KB
/
index.js
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
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const { v4: uuidv4 } = require('uuid');
const app = express();
app.use(bodyParser.json());
app.use(cors());
const licenses = [
{ key: 'M8ri4QG-g9hXQPqA-NQmSEOsU', devices: [], deviceLimit: 3 },
];
app.get('/get-uuid', (req, res) => {
const uuid = uuidv4();
res.json({ uuid });
});
app.post('/check-license', (req, res) => {
const { licenseKey, deviceId } = req.body;
const license = licenses.find(lic => lic.key === licenseKey);
if (!license) {
return res.json({ valid: false });
}
if (license.devices.includes(deviceId)) {
return res.json({ valid: true });
}
if (license.devices.length >= license.deviceLimit) {
return res.json({ valid: false });
}
license.devices.push(deviceId);
console.log(license.devices);
return res.json({ valid: true });
});
app.listen(5000, () => {
console.log('License server running on port 5000');
});