diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/index.ts | 1 | ||||
-rw-r--r-- | server/controllers/webfinger.ts | 44 | ||||
-rw-r--r-- | server/controllers/well-known.ts | 31 |
3 files changed, 30 insertions, 46 deletions
diff --git a/server/controllers/index.ts b/server/controllers/index.ts index eaa2dd7c8..09d657aca 100644 --- a/server/controllers/index.ts +++ b/server/controllers/index.ts | |||
@@ -11,5 +11,4 @@ export * from './plugins' | |||
11 | export * from './services' | 11 | export * from './services' |
12 | export * from './static' | 12 | export * from './static' |
13 | export * from './tracker' | 13 | export * from './tracker' |
14 | export * from './webfinger' | ||
15 | export * from './well-known' | 14 | export * from './well-known' |
diff --git a/server/controllers/webfinger.ts b/server/controllers/webfinger.ts deleted file mode 100644 index 29ce01166..000000000 --- a/server/controllers/webfinger.ts +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | import cors from 'cors' | ||
2 | import express from 'express' | ||
3 | import { WEBSERVER } from '@server/initializers/constants' | ||
4 | import { asyncMiddleware } from '../middlewares' | ||
5 | import { webfingerValidator } from '../middlewares/validators' | ||
6 | |||
7 | const webfingerRouter = express.Router() | ||
8 | |||
9 | webfingerRouter.use(cors()) | ||
10 | |||
11 | webfingerRouter.get('/.well-known/webfinger', | ||
12 | asyncMiddleware(webfingerValidator), | ||
13 | webfingerController | ||
14 | ) | ||
15 | |||
16 | // --------------------------------------------------------------------------- | ||
17 | |||
18 | export { | ||
19 | webfingerRouter | ||
20 | } | ||
21 | |||
22 | // --------------------------------------------------------------------------- | ||
23 | |||
24 | function webfingerController (req: express.Request, res: express.Response) { | ||
25 | const actor = res.locals.actorUrl | ||
26 | |||
27 | const json = { | ||
28 | subject: req.query.resource, | ||
29 | aliases: [ actor.url ], | ||
30 | links: [ | ||
31 | { | ||
32 | rel: 'self', | ||
33 | type: 'application/activity+json', | ||
34 | href: actor.url | ||
35 | }, | ||
36 | { | ||
37 | rel: 'http://ostatus.org/schema/1.0/subscribe', | ||
38 | template: WEBSERVER.URL + '/remote-interaction?uri={uri}' | ||
39 | } | ||
40 | ] | ||
41 | } | ||
42 | |||
43 | return res.json(json) | ||
44 | } | ||
diff --git a/server/controllers/well-known.ts b/server/controllers/well-known.ts index ce5883571..bb9acfb37 100644 --- a/server/controllers/well-known.ts +++ b/server/controllers/well-known.ts | |||
@@ -1,16 +1,21 @@ | |||
1 | import cors from 'cors' | 1 | import cors from 'cors' |
2 | import express from 'express' | 2 | import express from 'express' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { asyncMiddleware, handleStaticError, webfingerValidator } from '@server/middlewares' | ||
4 | import { root } from '@shared/core-utils' | 5 | import { root } from '@shared/core-utils' |
5 | import { CONFIG } from '../initializers/config' | 6 | import { CONFIG } from '../initializers/config' |
6 | import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' | 7 | import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' |
7 | import { cacheRoute } from '../middlewares/cache/cache' | 8 | import { cacheRoute } from '../middlewares/cache/cache' |
8 | import { handleStaticError } from '@server/middlewares' | ||
9 | 9 | ||
10 | const wellKnownRouter = express.Router() | 10 | const wellKnownRouter = express.Router() |
11 | 11 | ||
12 | wellKnownRouter.use(cors()) | 12 | wellKnownRouter.use(cors()) |
13 | 13 | ||
14 | wellKnownRouter.get('/.well-known/webfinger', | ||
15 | asyncMiddleware(webfingerValidator), | ||
16 | webfingerController | ||
17 | ) | ||
18 | |||
14 | wellKnownRouter.get('/.well-known/security.txt', | 19 | wellKnownRouter.get('/.well-known/security.txt', |
15 | cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT), | 20 | cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT), |
16 | (_, res: express.Response) => { | 21 | (_, res: express.Response) => { |
@@ -81,3 +86,27 @@ wellKnownRouter.use('/.well-known/', | |||
81 | export { | 86 | export { |
82 | wellKnownRouter | 87 | wellKnownRouter |
83 | } | 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 | } | ||