@polka/parse: wildcards are unsupported
rschristian opened this issue · comments
Hello,
I'm not sure whether this is something in the scope or another part of the Express-specific behaviors, but I ran across an issue replacing Express's raw()
with Polka's.
A server I'm converting to use Polka was using express.raw({ type: '*/*' })
. However, I can't swap that out for Polka's raw()
as wildcards don't seem to be handled currently:
Line 18 in 3b4d866
As the type
that I have passed to the raw parser is never going to mach up with the Content-Type
header, no parsing will ever be done.
Hey, no wildcard but you can use an empty string to accept everything. You can also provide any value so long as it's included -- you can use this to match groups for example (eg image/
)
Oh, looks like I then guessed at the wrong issue. Odd.
I did a one-off test where I set the type
to application/json
and it worked without a hitch, so I assumed that was the problem. I do need to accept all content types however, so this isn't a long-term solution.
Strangely I get an empty object instead of a parsed value when using an empty string / any other value. Will need to look into that further.
Edit: I don't believe an empty string will work properly as it will fall back to the default:
Line 65 in 3b4d866
Sorry, I meant to say that my suggestion was tied to the parse
export, since there's no default there. Its exported so that you can roll your own anything. All named exports are named commons (and align with body-parser
defaults iirc)
import { parse } from '@polka/parse';
polka()
.use(
parse({
type: '',
encoding: null // to match raw
})
)
If you just want to use raw
, you can pass type: '/'
so that it doesn't fall through 😉
Ah, apologies. Should've realized that's what you meant.
Good point about type: '/'
too, didn't dawn on me 😅
All's working great, so I'll close this out. Thank you!