diff options
Diffstat (limited to 'server/controllers/well-known.ts')
-rw-r--r-- | server/controllers/well-known.ts | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/server/controllers/well-known.ts b/server/controllers/well-known.ts deleted file mode 100644 index 322cf6ea2..000000000 --- a/server/controllers/well-known.ts +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | import cors from 'cors' | ||
2 | import express from 'express' | ||
3 | import { join } from 'path' | ||
4 | import { asyncMiddleware, buildRateLimiter, 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 | const wellKnownRateLimiter = buildRateLimiter({ | ||
13 | windowMs: CONFIG.RATES_LIMIT.WELL_KNOWN.WINDOW_MS, | ||
14 | max: CONFIG.RATES_LIMIT.WELL_KNOWN.MAX | ||
15 | }) | ||
16 | |||
17 | wellKnownRouter.use(cors()) | ||
18 | |||
19 | wellKnownRouter.get('/.well-known/webfinger', | ||
20 | wellKnownRateLimiter, | ||
21 | asyncMiddleware(webfingerValidator), | ||
22 | webfingerController | ||
23 | ) | ||
24 | |||
25 | wellKnownRouter.get('/.well-known/security.txt', | ||
26 | wellKnownRateLimiter, | ||
27 | cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT), | ||
28 | (_, res: express.Response) => { | ||
29 | res.type('text/plain') | ||
30 | return res.send(CONFIG.INSTANCE.SECURITYTXT + CONFIG.INSTANCE.SECURITYTXT_CONTACT) | ||
31 | } | ||
32 | ) | ||
33 | |||
34 | // nodeinfo service | ||
35 | wellKnownRouter.use('/.well-known/nodeinfo', | ||
36 | wellKnownRateLimiter, | ||
37 | cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO), | ||
38 | (_, res: express.Response) => { | ||
39 | return res.json({ | ||
40 | links: [ | ||
41 | { | ||
42 | rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0', | ||
43 | href: WEBSERVER.URL + '/nodeinfo/2.0.json' | ||
44 | } | ||
45 | ] | ||
46 | }) | ||
47 | } | ||
48 | ) | ||
49 | |||
50 | // dnt-policy.txt service (see https://www.eff.org/dnt-policy) | ||
51 | wellKnownRouter.use('/.well-known/dnt-policy.txt', | ||
52 | wellKnownRateLimiter, | ||
53 | cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY), | ||
54 | (_, res: express.Response) => { | ||
55 | res.type('text/plain') | ||
56 | |||
57 | return res.sendFile(join(root(), 'dist/server/static/dnt-policy/dnt-policy-1.0.txt')) | ||
58 | } | ||
59 | ) | ||
60 | |||
61 | // dnt service (see https://www.w3.org/TR/tracking-dnt/#status-resource) | ||
62 | wellKnownRouter.use('/.well-known/dnt/', | ||
63 | wellKnownRateLimiter, | ||
64 | (_, res: express.Response) => { | ||
65 | res.json({ tracking: 'N' }) | ||
66 | } | ||
67 | ) | ||
68 | |||
69 | wellKnownRouter.use('/.well-known/change-password', | ||
70 | wellKnownRateLimiter, | ||
71 | (_, res: express.Response) => { | ||
72 | res.redirect('/my-account/settings') | ||
73 | } | ||
74 | ) | ||
75 | |||
76 | wellKnownRouter.use('/.well-known/host-meta', | ||
77 | wellKnownRateLimiter, | ||
78 | (_, res: express.Response) => { | ||
79 | res.type('application/xml') | ||
80 | |||
81 | const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' + | ||
82 | '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">\n' + | ||
83 | ` <Link rel="lrdd" type="application/xrd+xml" template="${WEBSERVER.URL}/.well-known/webfinger?resource={uri}"/>\n` + | ||
84 | '</XRD>' | ||
85 | |||
86 | res.send(xml).end() | ||
87 | } | ||
88 | ) | ||
89 | |||
90 | wellKnownRouter.use('/.well-known/', | ||
91 | wellKnownRateLimiter, | ||
92 | cacheRoute(ROUTE_CACHE_LIFETIME.WELL_KNOWN), | ||
93 | express.static(CONFIG.STORAGE.WELL_KNOWN_DIR, { fallthrough: false }), | ||
94 | handleStaticError | ||
95 | ) | ||
96 | |||
97 | // --------------------------------------------------------------------------- | ||
98 | |||
99 | export { | ||
100 | wellKnownRouter | ||
101 | } | ||
102 | |||
103 | // --------------------------------------------------------------------------- | ||
104 | |||
105 | function webfingerController (req: express.Request, res: express.Response) { | ||
106 | const actor = res.locals.actorUrl | ||
107 | |||
108 | const json = { | ||
109 | subject: req.query.resource, | ||
110 | aliases: [ actor.url ], | ||
111 | links: [ | ||
112 | { | ||
113 | rel: 'self', | ||
114 | type: 'application/activity+json', | ||
115 | href: actor.url | ||
116 | }, | ||
117 | { | ||
118 | rel: 'http://ostatus.org/schema/1.0/subscribe', | ||
119 | template: WEBSERVER.URL + '/remote-interaction?uri={uri}' | ||
120 | } | ||
121 | ] | ||
122 | } | ||
123 | |||
124 | return res.json(json) | ||
125 | } | ||