summaryrefslogtreecommitdiff
path: root/app/src/lib/server/beanstalkd.ts
blob: 10f392a977aff4fa9894e09a7481f6c42757d12b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import pkg from "beanstalkd";
import type { Handle } from "@sveltejs/kit";

// Annoying CommonJS interop issue (vitejs/vite#2139) which combines with incorrect typings from DefinitelyTyped project :(
// @ts-ignore
const BeanstalkdClient = pkg.default as typeof pkg;

export const beanstalkdHandle = (async ({ event, resolve }) => {
	// FIXME: Should obv. read from env.
	const beanstalkdClient = new BeanstalkdClient("localhost", 11300);
	await beanstalkdClient.connect();

	event.locals.beanstalkdClient = beanstalkdClient;
	try {
		return await resolve(event);
	} finally {
		beanstalkdClient.quit();
	}
}) satisfies Handle;