]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/well-known.ts
Avoid concurrency issue on transcoding
[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 { root } from '@shared/core-utils'
5 import { CONFIG } from '../initializers/config'
6 import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants'
7 import { cacheRoute } from '../middlewares/cache/cache'
8
9 const wellKnownRouter = express.Router()
10
11 wellKnownRouter.use(cors())
12
13 wellKnownRouter.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
22 wellKnownRouter.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)
37 wellKnownRouter.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)
47 wellKnownRouter.use('/.well-known/dnt/',
48 (_, res: express.Response) => {
49 res.json({ tracking: 'N' })
50 }
51 )
52
53 wellKnownRouter.use('/.well-known/change-password',
54 (_, res: express.Response) => {
55 res.redirect('/my-account/settings')
56 }
57 )
58
59 wellKnownRouter.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
74 export {
75 wellKnownRouter
76 }