]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/well-known.ts
Allow admins to disable two factor auth
[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 import { handleStaticError } from '@server/middlewares'
9
10 const wellKnownRouter = express.Router()
11
12 wellKnownRouter.use(cors())
13
14 wellKnownRouter.get('/.well-known/security.txt',
15 cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT),
16 (_, res: express.Response) => {
17 res.type('text/plain')
18 return res.send(CONFIG.INSTANCE.SECURITYTXT + CONFIG.INSTANCE.SECURITYTXT_CONTACT)
19 }
20 )
21
22 // nodeinfo service
23 wellKnownRouter.use('/.well-known/nodeinfo',
24 cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO),
25 (_, res: express.Response) => {
26 return res.json({
27 links: [
28 {
29 rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
30 href: WEBSERVER.URL + '/nodeinfo/2.0.json'
31 }
32 ]
33 })
34 }
35 )
36
37 // dnt-policy.txt service (see https://www.eff.org/dnt-policy)
38 wellKnownRouter.use('/.well-known/dnt-policy.txt',
39 cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY),
40 (_, res: express.Response) => {
41 res.type('text/plain')
42
43 return res.sendFile(join(root(), 'dist/server/static/dnt-policy/dnt-policy-1.0.txt'))
44 }
45 )
46
47 // dnt service (see https://www.w3.org/TR/tracking-dnt/#status-resource)
48 wellKnownRouter.use('/.well-known/dnt/',
49 (_, res: express.Response) => {
50 res.json({ tracking: 'N' })
51 }
52 )
53
54 wellKnownRouter.use('/.well-known/change-password',
55 (_, res: express.Response) => {
56 res.redirect('/my-account/settings')
57 }
58 )
59
60 wellKnownRouter.use('/.well-known/host-meta',
61 (_, res: express.Response) => {
62 res.type('application/xml')
63
64 const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' +
65 '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">\n' +
66 ` <Link rel="lrdd" type="application/xrd+xml" template="${WEBSERVER.URL}/.well-known/webfinger?resource={uri}"/>\n` +
67 '</XRD>'
68
69 res.send(xml).end()
70 }
71 )
72
73 wellKnownRouter.use('/.well-known/',
74 cacheRoute(ROUTE_CACHE_LIFETIME.WELL_KNOWN),
75 express.static(CONFIG.STORAGE.WELL_KNOWN_DIR, { fallthrough: false }),
76 handleStaticError
77 )
78
79 // ---------------------------------------------------------------------------
80
81 export {
82 wellKnownRouter
83 }