-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
2,121 additions
and
845 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Receiver } from '@upstash/qstash' | ||
import { memoize } from 'lodash' | ||
import { NextRequest } from 'next/server' | ||
|
||
import { Config, getConfig } from '@/lib/config' | ||
import { headerHost } from '@/lib/services/guards/headerHost' | ||
import { getQueue } from '@/lib/services/queue' | ||
import { logger } from '@/lib/utils/logger' | ||
import { apiErrorResponse, apiResponse } from '@/lib/utils/response' | ||
|
||
const getReceiver = memoize( | ||
(config: Config) => | ||
new Receiver({ | ||
currentSigningKey: config.queue?.currentSigningKey || '', | ||
nextSigningKey: config.queue?.nextSigningKey || '' | ||
}) | ||
) | ||
|
||
export const POST = async (request: NextRequest) => { | ||
const config = getConfig() | ||
if (config.queue?.type !== 'qstash') { | ||
return apiErrorResponse(404) | ||
} | ||
|
||
const receiver = getReceiver(config) | ||
const body = await request.text() | ||
const signature = request.headers.get('upstash-signature') ?? '' | ||
|
||
try { | ||
const isValid = await receiver.verify({ | ||
body, | ||
signature, | ||
url: `https://${headerHost(request.headers)}/api/v1/queue/qstash` | ||
}) | ||
if (!isValid) { | ||
return apiErrorResponse(400) | ||
} | ||
|
||
const jsonBody = JSON.parse(body) | ||
logger.debug({ body: jsonBody }, 'Received message from qstash') | ||
await getQueue().handle(jsonBody) | ||
} catch (e) { | ||
logger.error(e) | ||
return apiErrorResponse(400) | ||
} | ||
return apiResponse(request, ['POST'], {}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getConfig } from '@/lib/config' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export const GET = async () => { | ||
const config = getConfig() | ||
|
||
return Response.json({ | ||
links: [ | ||
{ | ||
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0', | ||
href: `https://${config.host}/.well-known/nodeinfo/2.0` | ||
} | ||
] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.