diff options
Diffstat (limited to 'app/src/lib/server/beanstalkd.ts')
-rw-r--r-- | app/src/lib/server/beanstalkd.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/src/lib/server/beanstalkd.ts b/app/src/lib/server/beanstalkd.ts new file mode 100644 index 0000000..10f392a --- /dev/null +++ b/app/src/lib/server/beanstalkd.ts @@ -0,0 +1,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; |