platformOS Community

[Solved] URL using two dots

Arie Apr 15 2021 at 02:36

I want to capture params using {{context.headers.REQUEST_URI}}
_next.liquid
{{context.headers.REQUEST_URI}}

/_next/static/chunks/hello.js

But when this URL has two dots

/_next/static/chunks/hello.there.js [its not working]. Its become 404

How to capture this params ?

Solution:
I put in config file "/assets"

Thanks

Pawel Apr 15 2021 at 08:04

Getting params might be easier to get from context.params ( https://documentation.platformos.com/developer-guide/variables/context-variable#content )

For example url:

https://documentation.platformos.com/release-notes/hello.there.js

Will return:

{"slug":"release-notes","slug2":"hello.there.js","slugs":"hello.there.js","format":"html"}

Having said that, i would say getting urls to webpack/next chunks is a bad idea. They should be loaded programmatically/dynamically from your main entrypoint.

Pawel Apr 22 2021 at 14:21

We use queryparams for cache busting of main files (app.js, app.css) so it looks like this:

app.js?v=200210421

(Read at https://github.com/mdyd-dev/platformos-documentation/blob/master/webpack.config.js#L15 )

And all the chunks (that are generated by webpack, nextJS probably too) are loaded by webpack (next) internals, because it has manifest of all the assets generated during build time.

To have dynamic CDN (because we use multiple instances, stagings, productions, etc.) URL we use a webpack plugin - read at:
https://github.com/mdyd-dev/platformos-documentation/blob/master/webpack.config.js#L52-L56

Generally it is worth the time to discover how particular framework can do relative paths to assets/chunks, because it will create a lot of problems down the road if its not simple and just works always.

Arie Apr 16 2021 at 01:26

Thanks Pawel.

I just thinking how to make it more simple after "npm run build" from NextJS without more changes of the result files.
Because every build the files name are always changed

Please sign in or fill up your profile to answer a question