diff options
author | Elizabeth Hunt <me@liz.coffee> | 2025-06-29 17:31:30 -0700 |
---|---|---|
committer | Elizabeth Hunt <me@liz.coffee> | 2025-06-29 17:31:30 -0700 |
commit | 58be1809c46cbe517a18d86d0af52179dcc5cbf6 (patch) | |
tree | 9ccc678b3fd48c1a52fe501600dd2c2051740a55 /u/server/filter/method.ts | |
parent | d4791f3d357634daf506fb8f91cc5332a794c421 (diff) | |
download | ci-58be1809c46cbe517a18d86d0af52179dcc5cbf6.tar.gz ci-58be1809c46cbe517a18d86d0af52179dcc5cbf6.zip |
Move to nodejs and also lots of significant refactoring that should've been broken up but idgaf
Diffstat (limited to 'u/server/filter/method.ts')
-rw-r--r-- | u/server/filter/method.ts | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/u/server/filter/method.ts b/u/server/filter/method.ts index 5ca5716..7d6aa76 100644 --- a/u/server/filter/method.ts +++ b/u/server/filter/method.ts @@ -1,5 +1,7 @@ import { Either, + HttpMethod, + IEither, type ITraceable, LogLevel, PenguenoError, @@ -9,24 +11,20 @@ import { TraceUtil, } from '@emprespresso/pengueno'; -type HttpMethod = 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH'; - export const requireMethod = (methods: Array<HttpMethod>): RequestFilter<HttpMethod> => (req: ITraceable<PenguenoRequest, ServerTrace>) => req - .bimap(TraceUtil.withFunctionTrace(requireMethod)) - .move(Promise.resolve(req.get())) - .map( - TraceUtil.promiseify((t) => { - const { method: _method } = t.get(); - const method = <HttpMethod>_method; - if (!methods.includes(method)) { - const msg = "that's not how you pet me (⋟﹏⋞)~"; - t.trace.addTrace(LogLevel.WARN).trace(msg); - return Either.left<PenguenoError, HttpMethod>(new PenguenoError(msg, 405)); - } - return Either.right<PenguenoError, HttpMethod>(method); - }), - ) + .flatMap(TraceUtil.withFunctionTrace(requireMethod)) + .map((t): IEither<PenguenoError, HttpMethod> => { + const { + req: { method }, + } = t.get(); + if (!methods.includes(method)) { + const msg = "that's not how you pet me (⋟﹏⋞)~"; + t.trace.traceScope(LogLevel.WARN).trace(msg); + return Either.left(new PenguenoError(msg, 405)); + } + return Either.right(method); + }) .get(); |