-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
5_subdomain_spec.ts
130 lines (106 loc) · 2.42 KB
/
5_subdomain_spec.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import cors from 'cors'
import parser from 'cookie-parser'
import session from 'express-session'
import e2e from '../support/helpers/e2e'
const onServer = function (app) {
app.use(parser())
app.use((req, res, next) => {
console.log('** REQUEST HEADERS ARE', req.url, req.headers)
return next()
})
const getIndex = () => {
return `\
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ul>
<li>
<a href="http://help.foobar.com:2292">switch to http://help.foobar.com</a>
</li>
</ul>
</body>
</html>\
`
}
const getText = (text) => {
return `\
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>${text}</h1>
</body>
</html>\
`
}
const applySession = session({
name: 'secret-session',
secret: 'secret',
cookie: {
sameSite: true,
},
}) as Function
app.get('/htmlCookies', (req, res) => {
const {
cookie,
} = req.headers
return res.send(`<html><div id='cookie'>${cookie}</div></html>`)
})
app.get('/cookies*', cors({ origin: true, credentials: true }), (req, res) => {
return res.json({
cookie: req.headers['cookie'],
parsed: req.cookie,
})
})
app.get('/redirect', (req, res) => {
return res.redirect('http://www.foobar.com:2292/cookies')
})
app.get('/domainRedirect', (req, res) => {
return res.redirect('http://www.foobar.com:2292/htmlCookies')
})
return app.get('*', (req, res, next) => {
res.set('Content-Type', 'text/html')
const getHtml = () => {
let h
switch ((h = req.get('host'))) {
case 'www.foobar.com:2292':
return getIndex()
case 'help.foobar.com:2292':
return getText('Help')
case 'session.foobar.com:2292':
applySession(req, res, next)
return getText('Session')
case 'domain.foobar.com:2292':
res.cookie('nomnom', 'good', {
domain: '.foobar.com',
})
return getText('Domain')
case 'qa.sub.foobar.com:2292': case 'staging.sub.foobar.com:2292':
return getText('Nested Subdomains')
default:
throw new Error(`Host: '${h}' not recognized`)
}
}
return res.send(getHtml())
})
}
describe('e2e subdomain', () => {
e2e.setup({
servers: {
port: 2292,
onServer,
},
})
e2e.it('passes', {
spec: 'subdomain_spec.coffee',
snapshot: true,
config: {
hosts: {
'*.foobar.com': '127.0.0.1',
},
},
})
})