mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-13 13:37:31 -07:00
Allow CORS requests in /.well-known/* routes (#5717)
* Allow CORS requests in /.well-known/* routes * Fix bug
This commit is contained in:
parent
fc1d683d3d
commit
ecb2dc245c
1 changed files with 16 additions and 1 deletions
|
@ -19,10 +19,25 @@ const XRD = (...x: { element: string, value?: string, attributes?: Record<string
|
|||
typeof value === 'string' ? `>${escapeValue(value)}</${element}` : '/'
|
||||
}>`).reduce((a, c) => a + c, '')}</XRD>`;
|
||||
|
||||
const allPath = '/.well-known/*';
|
||||
const webFingerPath = '/.well-known/webfinger';
|
||||
const jrd = 'application/jrd+json';
|
||||
const xrd = 'application/xrd+xml';
|
||||
|
||||
router.use(allPath, async (ctx, next) => {
|
||||
ctx.set({
|
||||
'Access-Control-Allow-Headers': 'Accept',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Expose-Headers': 'Vary',
|
||||
});
|
||||
await next();
|
||||
});
|
||||
|
||||
router.options(allPath, async ctx => {
|
||||
ctx.status = 204;
|
||||
});
|
||||
|
||||
router.get('/.well-known/host-meta', async ctx => {
|
||||
ctx.set('Content-Type', xrd);
|
||||
ctx.body = XRD({ element: 'Link', attributes: {
|
||||
|
@ -123,7 +138,7 @@ router.get(webFingerPath, async ctx => {
|
|||
});
|
||||
|
||||
// Return 404 for other .well-known
|
||||
router.all('/.well-known/*', async ctx => {
|
||||
router.all(allPath, async ctx => {
|
||||
ctx.status = 404;
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue