2
1

webfinger.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as cors from 'cors'
  2. import * as express from 'express'
  3. import { WEBSERVER } from '@server/initializers/constants'
  4. import { asyncMiddleware } from '../middlewares'
  5. import { webfingerValidator } from '../middlewares/validators'
  6. const webfingerRouter = express.Router()
  7. webfingerRouter.use(cors())
  8. webfingerRouter.get('/.well-known/webfinger',
  9. asyncMiddleware(webfingerValidator),
  10. webfingerController
  11. )
  12. // ---------------------------------------------------------------------------
  13. export {
  14. webfingerRouter
  15. }
  16. // ---------------------------------------------------------------------------
  17. function webfingerController (req: express.Request, res: express.Response) {
  18. const actor = res.locals.actorUrl
  19. const json = {
  20. subject: req.query.resource,
  21. aliases: [ actor.url ],
  22. links: [
  23. {
  24. rel: 'self',
  25. type: 'application/activity+json',
  26. href: actor.url
  27. },
  28. {
  29. rel: 'http://ostatus.org/schema/1.0/subscribe',
  30. template: WEBSERVER.URL + '/remote-interaction?uri={uri}'
  31. }
  32. ]
  33. }
  34. return res.json(json)
  35. }