-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfibonacci-sequence.js
46 lines (36 loc) · 1.03 KB
/
fibonacci-sequence.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
import express from 'express';
import { FIBONACCI_SERVER_PORT, FIBONACCI_PATH, REQUEST_TIMEOUT } from '../config.js';
import { getFibonacciSequence } from '../functions/fibonacci-sequence.js';
import { printDistributedServiceEvent } from '../utils/print.js';
const app = express();
app.use(express.json());
app.post(FIBONACCI_PATH, async (request, response) => {
const {
parent,
input,
context
// info
} = request.body;
printDistributedServiceEvent({
name: 'fibonacci sequence',
body: {
parent,
input,
context
// info
}
});
const fibonacciSequence = getFibonacciSequence();
const result = context.authScope.numbers === true ?
fibonacciSequence :
fibonacciSequence.filter(i => context.authScope.numbers.includes(i));
response.send(result);
});
app.listen(
{ port: FIBONACCI_SERVER_PORT },
() => console.log(
`🚀🚀🚀 fibonacci sequence distributed service running at localhost:${FIBONACCI_SERVER_PORT}${FIBONACCI_PATH}`
)
).setTimeout(
REQUEST_TIMEOUT
);