quirrel-dev / quirrel

The Task Queueing Solution for Serverless.
https://quirrel.dev
MIT License
885 stars 67 forks source link

"Signature is missing" when using quirrel with sveltekit in production mode #1128

Closed bamthomas closed 1 year ago

bamthomas commented 1 year ago

Bug Report

Current Behavior When using quirrel with sveltekit in production we have the error Signature is missing when quirrel calls the app.

The code :

async respondTo(
    body: string,
    headers: IncomingHttpHeaders
  ): Promise<{
    status: number;
    headers: Record<string, string>;
    body: string;
  }> {
    if (process‧env.NODE_ENV === "production") {
      const signature = headers["x-quirrel-signature"];
      if (typeof signature !== "string") {
        return {
          status: 401,
          headers: {},
          body: "Signature missing",
        };
      }
    // ....
    }

Is getting undefined in the signature variable.

It seems that headers object is a Map and I'm not sure we can read the header with headers["x-quirrel-signature"] :

[Symbol(headers map)]: Map(9) {                                                                                                                                                                                  
    'content-type' => { name: 'content-type', value: 'text/plain' },                                                                                                                                                                                                                                                                                                                                      
    'x-quirrel-signature' => {                                                                                                                                                                                     
      name: 'x-quirrel-signature',                                                                                                                                                                                 
      value: '<signature>'                                                                                                                  
    },                                                                                                                                                                                                             
  // ....                                                                                                                                   
  },                                                                                                                                                                                                               
  [Symbol(headers map sorted)]: null                                                                                                                                                                               
}                                             

Expected behavior/code

The header is correctly read.

Environment

Possible Solution

I'm not sure how to fix this (that's the reason I didn't make a PR) because :

headers‧get('x-quirrel-signature')

is working but maybe it won't work for other environments.

maybe :

const signature = typeof headers === 'Map' ? headers‧get('x-quirrel-signature') : headers['x-quirrel-signature]

What do you think ? As a workaround I'm doing a sed in the file while building my app.

Skn0tt commented 1 year ago

Thanks for the detailed report! Looks like SvelteKit changed the types of the request object. I'm working on a fix in https://github.com/quirrel-dev/quirrel/pull/1131, will ping here when it's released.

@all-contributors please add @bamthomas for bug

allcontributors[bot] commented 1 year ago

@Skn0tt

I couldn't determine any contributions to add, did you specify any contributions? Please make sure to use valid contribution names.

I've put up a pull request to add @bamthomas! :tada:

Skn0tt commented 1 year ago

Shipped in https://github.com/quirrel-dev/quirrel/releases/tag/v1.13.3, please let me know if that works for you.

bamthomas commented 1 year ago

Thank you very much for the fix and the add.

I'm going to test it soon, I will update this comment.