fix(routes/api): handle non websocket connection
This commit is contained in:
parent
fba0c18aa8
commit
595b9518d5
|
|
@ -2,6 +2,15 @@ import { define } from '../../../utils.ts'
|
||||||
|
|
||||||
export const handler = define.handlers({
|
export const handler = define.handlers({
|
||||||
GET(ctx) {
|
GET(ctx) {
|
||||||
|
if (
|
||||||
|
ctx.req.headers.get('connection') !== 'Upgrade' &&
|
||||||
|
ctx.req.headers.get('upgrade') !== 'websocket'
|
||||||
|
) {
|
||||||
|
return new Response('Request is not a websocket upgrade.', {
|
||||||
|
status: 400,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const { response } = Deno.upgradeWebSocket(ctx.req)
|
const { response } = Deno.upgradeWebSocket(ctx.req)
|
||||||
ctx.state.skipMiddlewares = true
|
ctx.state.skipMiddlewares = true
|
||||||
return response
|
return response
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue