-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathmessage-server.ts
More file actions
113 lines (96 loc) · 4.04 KB
/
Copy pathmessage-server.ts
File metadata and controls
113 lines (96 loc) · 4.04 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { getLocal, Mockttp } from 'mockttp';
import { getDeferred } from '@httptoolkit/util';
import { HtkConfig } from './config';
import { EPHEMERAL_PORT_RANGE } from './constants';
export class MessageServer {
constructor(
private config: HtkConfig,
private message: string
) { }
private server: Mockttp | undefined;
private messageSeen = getDeferred();
async start() {
this.server = getLocal({ https: this.config.https, cors: true });
await this.server.start(EPHEMERAL_PORT_RANGE);
await this.server.forGet('/')
.thenCallback(() => {
console.log('Request to message server received');
this.messageSeen.resolve();
return {
statusCode: 200,
body: `
<html>
<title>HTTP Toolkit</title>
<meta charset="UTF-8" />
<link href="http://fonts.googleapis.com/css?family=Lato" rel="stylesheet" />
<style>
body {
margin: 0;
padding: 20px;
background-color: #d8e2e6;
font-family: Lato, Arial;
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 100%;
box-sizing: border-box;
text-align: center;
}
p {
font-size: 16pt;
}
iframe {
display: none;
}
</style>
<body>
<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px"
y="0px"
width="400px"
height="400px"
viewBox="0 0 50 50"
style="enable-background:new 0 0 50 50;"
>
<path fill="#b6c2ca" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z">
<animateTransform
attributeType="xml"
attributeName="transform"
type="rotate"
from="0 25 25"
to="360 25 25"
dur="6s"
repeatCount="indefinite"
/>
</path>
</svg>
<p>
${this.message}
</p>
</div>
</body>
</html>
`
};
});
}
get host(): string {
return this.server!.url
.replace('https://', '');
}
get url(): string {
return this.server!.url.replace('https://', 'http://');
}
async waitForSuccess(): Promise<void> {
await this.messageSeen.promise;
}
async stop() {
if (this.server) {
await this.server.stop();
this.server = undefined;
}
}
}