-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequence.mjs
More file actions
27 lines (20 loc) · 768 Bytes
/
sequence.mjs
File metadata and controls
27 lines (20 loc) · 768 Bytes
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
import http from 'node:http';
import {getPrimeMultipliers} from "./getPrimeMultipliers.mjs";
BigInt.prototype.toJSON = function() { return this.toString() }
const makeResponse = (res, data) => {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(data));
}
const server = http.createServer((req, res) => {
const { pathname } = new URL(req.url, `http://${req.headers.host}`);
const numberToCalc = BigInt(pathname.substring(1)) || BigInt(2);
const arrayOfMultipliers = getPrimeMultipliers(numberToCalc);
makeResponse(res, arrayOfMultipliers);
});
process.on('uncaughtException', (err) => {
console.error(err);
});
process.on('unhandledRejection', (err) => {
console.error(err);
})
server.listen(3000);