-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
71 lines (61 loc) · 1.76 KB
/
app.ts
File metadata and controls
71 lines (61 loc) · 1.76 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
65
66
67
68
69
70
71
import express, { Request, Response, NextFunction } from 'express';
import split = require('@splitsoftware/splitio');
interface LocationWithTimezone {
location: string;
timezoneName: string;
timezoneAbbr: string;
utcOffset: number;
};
const app = express();
const port = 3000;
app.listen(port, () => {
console.log(`Timezones by location application is running on port ${port}.`);
});
const factory: SplitIO.ISDK = split.SplitFactory({
core: {
authorizationKey: '7m4qctr1k6vi9kshbbu972vqm8nklom6qnjh'
}
});
const client: SplitIO.IClient = factory.client();
const getLocationsWithTimezones = (request: Request, response: Response, next: NextFunction) => {
let locations: LocationWithTimezone[] = [
{
location: 'Germany',
timezoneName: 'Central European Time',
timezoneAbbr: 'CET',
utcOffset: 1
},
{
location: 'China',
timezoneName: 'China Standard Time',
timezoneAbbr: 'CST',
utcOffset: 8
},
{
location: 'Argentina',
timezoneName: 'Argentina Time',
timezoneAbbr: 'ART',
utcOffset: -3
},
{
location: 'Japan',
timezoneName: 'Japan Standard Time',
timezoneAbbr: 'JST',
utcOffset: 9
}
];
if (request.treatment == 'on')
locations.push({
location: 'Kenya',
timezoneName: 'Eastern Africa Time',
timezoneAbbr: 'EAT',
utcOffset: 3
});
response.status(200).json(locations);
};
const getTreatmentMiddleware = function (request: Request, response: Response, next: NextFunction) {
const key: SplitIO.SplitKey = <SplitIO.SplitKey>request.headers['authorization'];
request.treatment = client.getTreatment(key, 'timezone_split');
next();
};
app.get('/timezones', getTreatmentMiddleware, getLocationsWithTimezones);