aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/well-known.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-07-13 11:13:19 +0200
committerChocobozzz <me@florianbigard.com>2022-07-13 11:16:29 +0200
commitea8107bff8e544594716a76d30ff372fc80d755c (patch)
treec2383e0e9cd1298ff12106073086721edb5fb441 /server/controllers/well-known.ts
parentc5cadb2859050449596199090231d6e38bc4a571 (diff)
downloadPeerTube-ea8107bff8e544594716a76d30ff372fc80d755c.tar.gz
PeerTube-ea8107bff8e544594716a76d30ff372fc80d755c.tar.zst
PeerTube-ea8107bff8e544594716a76d30ff372fc80d755c.zip
Split static router
Diffstat (limited to 'server/controllers/well-known.ts')
-rw-r--r--server/controllers/well-known.ts76
1 files changed, 76 insertions, 0 deletions
diff --git a/server/controllers/well-known.ts b/server/controllers/well-known.ts
new file mode 100644
index 000000000..f467bd629
--- /dev/null
+++ b/server/controllers/well-known.ts
@@ -0,0 +1,76 @@
1import cors from 'cors'
2import express from 'express'
3import { join } from 'path'
4import { root } from '@shared/core-utils'
5import { CONFIG } from '../initializers/config'
6import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants'
7import { cacheRoute } from '../middlewares/cache/cache'
8
9const wellKnownRouter = express.Router()
10
11wellKnownRouter.use(cors())
12
13wellKnownRouter.get('/.well-known/security.txt',
14 cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT),
15 (_, res: express.Response) => {
16 res.type('text/plain')
17 return res.send(CONFIG.INSTANCE.SECURITYTXT + CONFIG.INSTANCE.SECURITYTXT_CONTACT)
18 }
19)
20
21// nodeinfo service
22wellKnownRouter.use('/.well-known/nodeinfo',
23 cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO),
24 (_, res: express.Response) => {
25 return res.json({
26 links: [
27 {
28 rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
29 href: WEBSERVER.URL + '/nodeinfo/2.0.json'
30 }
31 ]
32 })
33 }
34)
35
36// dnt-policy.txt service (see https://www.eff.org/dnt-policy)
37wellKnownRouter.use('/.well-known/dnt-policy.txt',
38 cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY),
39 (_, res: express.Response) => {
40 res.type('text/plain')
41
42 return res.sendFile(join(root(), 'dist/server/static/dnt-policy/dnt-policy-1.0.txt'))
43 }
44)
45
46// dnt service (see https://www.w3.org/TR/tracking-dnt/#status-resource)
47wellKnownRouter.use('/.well-known/dnt/',
48 (_, res: express.Response) => {
49 res.json({ tracking: 'N' })
50 }
51)
52
53wellKnownRouter.use('/.well-known/change-password',
54 (_, res: express.Response) => {
55 res.redirect('/my-account/settings')
56 }
57)
58
59wellKnownRouter.use('/.well-known/host-meta',
60 (_, res: express.Response) => {
61 res.type('application/xml')
62
63 const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' +
64 '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">\n' +
65 ` <Link rel="lrdd" type="application/xrd+xml" template="${WEBSERVER.URL}/.well-known/webfinger?resource={uri}"/>\n` +
66 '</XRD>'
67
68 res.send(xml).end()
69 }
70)
71
72// ---------------------------------------------------------------------------
73
74export {
75 wellKnownRouter
76}