Open kiuKisas opened 3 years ago
A quick fix will be to add encodeURI
to permalink in dev mode, but it doesn't feel right as it can prevent some error in permalink to show in dev mode but will be there in build mode.
I guess it as something to do with polka
configuration..
I'll ping @lukeed about what Polka may be doing.
Hey,
I'm assuming that @kiuKisas started with the template. If so, that's using polka@0.5.2
which does not decode URLs by default. This was changed within polka@next
. You can change this by installing and attaching @polka/url@next
, which also happens to be the same parser that sirv
uses. Here's the how-to
Beyond that, I would need some kind of minimal repro to see what (else?) is going on as I'm unfortunately not super familiar with all the moving pieces here
Just to confirm – that should be the fix since Polka is setting req.path
which sirv
then respects & uses, preventing its own decode.
Your directory name should contain the special characters. It worked in dev because your filesystem also contained the special characters, but the in-memory FILES cache of sirv
possessed keys like /salamèche
, but the req.path
was sending the still-encoded /salam%C3%A8che
form.
I had more time to try it out, and it works indeed ! Just to recap if someone need it right now, this is the way to go:
add polka/url@next to your project:
yarn add polka/url@next
add the parser to your config in src/server.js
:
const parser = require('@polka/url');
server.parse = (req) => parser(req, true);
Let's say I have a permalink with an accent, for exemple
/salamèche
. Indev mode
, when I try to access the page, I get aNot Found
page. When Ibuild
, I get the correct pathsalamèche
in my public folder and I can access the page as expected.I tried to wrap my permalink with
encodeURI
function. It work now indev mode
, when I build, it create the foldersalam%C3%A8che
but I can't access this page (withsirv-cli
), either with/salamèche
or/salam%C3%A8che
.