-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
49 lines (40 loc) · 1020 Bytes
/
app.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
import express from 'express'
const app = express()
const port = 3000
type urlMap = {
[key: string]: string
}
const shoppingDestinationUrls: urlMap = {
'home': '/',
'accessibility-statement': '/accessibility',
'contact': '/contact',
'help': '/help',
'log-in': '/sign-in',
'products': '/products'
} as const
function main() {
let siteName: string
let destinationUrls: urlMap
switch (process.argv.at(-1)) {
case 'shopping':
siteName = 'shopping'
destinationUrls = shoppingDestinationUrls
break
default:
console.log('Usage: app.ts <site>\n Valid sites are: shopping')
return
}
app.use(express.static(`demo-site-${siteName}/public`))
app.get('/.well-known/ia', (req, res) => {
res.send(Object.keys(destinationUrls))
})
for (const [ dest, url ] of Object.entries(destinationUrls)) {
app.get(`/.well-known/ia/${dest}`, (req, res) => {
res.redirect(url)
})
}
app.listen(port, () => {
console.log(`Example app (${siteName}) listening on port ${port}`)
})
}
main()