]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/well-known.ts
Add x-powered-by header
[github/Chocobozzz/PeerTube.git] / server / controllers / well-known.ts
1 import cors from 'cors'
2 import express from 'express'
3 import { join } from 'path'
4 import { asyncMiddleware, handleStaticError, webfingerValidator } from '@server/middlewares'
5 import { root } from '@shared/core-utils'
6 import { CONFIG } from '../initializers/config'
7 import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants'
8 import { cacheRoute } from '../middlewares/cache/cache'
9
10 const wellKnownRouter = express.Router()
11
12 wellKnownRouter.use(cors())
13
14 wellKnownRouter.get('/.well-known/webfinger',
15 asyncMiddleware(webfingerValidator),
16 webfingerController
17 )
18
19 wellKnownRouter.get('/.well-known/security.txt',
20 cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT),
21 (_, res: express.Response) => {
22 res.type('text/plain')
23 return res.send(CONFIG.INSTANCE.SECURITYTXT + CONFIG.INSTANCE.SECURITYTXT_CONTACT)
24 }
25 )
26
27 // nodeinfo service
28 wellKnownRouter.use('/.well-known/nodeinfo',
29 cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO),
30 (_, res: express.Response) => {
31 return res.json({
32 links: [
33 {
34 rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
35 href: WEBSERVER.URL + '/nodeinfo/2.0.json'
36 }
37 ]
38 })
39 }
40 )
41
42 // dnt-policy.txt service (see https://www.eff.org/dnt-policy)
43 wellKnownRouter.use('/.well-known/dnt-policy.txt',
44 cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY),
45 (_, res: express.Response) => {
46 res.type('text/plain')
47
48 return res.sendFile(join(root(), 'dist/server/static/dnt-policy/dnt-policy-1.0.txt'))
49 }
50 )
51
52 // dnt service (see https://www.w3.org/TR/tracking-dnt/#status-resource)
53 wellKnownRouter.use('/.well-known/dnt/',
54 (_, res: express.Response) => {
55 res.json({ tracking: 'N' })
56 }
57 )
58
59 wellKnownRouter.use('/.well-known/change-password',
60 (_, res: express.Response) => {
61 res.redirect('/my-account/settings')
62 }
63 )
64
65 wellKnownRouter.use('/.well-known/host-meta',
66 (_, res: express.Response) => {
67 res.type('application/xml')
68
69 const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' +
70 '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">\n' +
71 ` <Link rel="lrdd" type="application/xrd+xml" template="${WEBSERVER.URL}/.well-known/webfinger?resource={uri}"/>\n` +
72 '</XRD>'
73
74 res.send(xml).end()
75 }
76 )
77
78 wellKnownRouter.use('/.well-known/',
79 cacheRoute(ROUTE_CACHE_LIFETIME.WELL_KNOWN),
80 express.static(CONFIG.STORAGE.WELL_KNOWN_DIR, { fallthrough: false }),
81 handleStaticError
82 )
83
84 // ---------------------------------------------------------------------------
85
86 export {
87 wellKnownRouter
88 }
89
90 // ---------------------------------------------------------------------------
91
92 function webfingerController (req: express.Request, res: express.Response) {
93 const actor = res.locals.actorUrl
94
95 const json = {
96 subject: req.query.resource,
97 aliases: [ actor.url ],
98 links: [
99 {
100 rel: 'self',
101 type: 'application/activity+json',
102 href: actor.url
103 },
104 {
105 rel: 'http://ostatus.org/schema/1.0/subscribe',
106 template: WEBSERVER.URL + '/remote-interaction?uri={uri}'
107 }
108 ]
109 }
110
111 return res.json(json)
112 }