import { define } from '../../../utils.ts'

export const handler = define.handlers({
	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)
		ctx.state.skipMiddlewares = true
		return response
	},
})
