-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
51 lines (38 loc) · 1.44 KB
/
index.ts
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
import express from 'express';
import * as sameOriginPolicy from './src/same-origin-policy';
import * as cors from './src/cors';
import { headerLoggerMiddleware } from './src/middleware/header';
const webPort = 3000;
const serverPort = 3001;
function startWebServer() {
const server = express();
server.use('/same-origin-policy', sameOriginPolicy.web());
server.use('/cors', cors.web());
server.listen(webPort);
console.log(`Web server started at http://localhost:${webPort}`);
}
function startResourceServer() {
const server = express();
server.use(headerLoggerMiddleware);
// same-origin policy
server.use('/same-origin-policy', sameOriginPolicy.router());
// cors
const corsPath = '/cors';
// Note that preflight failed routers must be used in the first place
// Otherwise, other routers might change the server cors behavior
server.use(corsPath, cors.preflightFailedOriginRouter());
server.use(corsPath, cors.preflightFailedMethodRouter());
server.use(corsPath, cors.preflightFailedHeaderRouter());
server.use(corsPath, cors.preflightCachedRouter());
server.use(corsPath, cors.simpleRouter());
server.use(corsPath, cors.wildcardSimpleRouter());
server.use(corsPath, cors.credentials());
server.use(corsPath, cors.notExposeHeaders());
server.listen(serverPort);
console.log(`Resource server started at http://localhost:${serverPort}`);
}
function main() {
startWebServer();
startResourceServer();
}
main();