Open Shana-AE opened 1 week ago
Hi @Shana-AE
The issue is that the /path
component is lost ?
Hi @Shana-AE The issue is that the
/path
component is lost ?
yes, relativeUrl
starts with /
, so /path
is lost
https://github.com/Baroshem/nuxt-security/blob/f7d989c95440a043193bd97325d4a97908f916fc/src/module.ts#L307
Yes you're right
By the way, is there any way to modify the sriHashes at runtime? The fact is I have two cdn for different geo location users. I want to use different cdnURL according to user location. I'm using scripts to duplicate static files and modify cdnURL after build, but for sriHashes, only a replacement is not enough, so is that parsing and adding another set of cdn sriHashes the only solution?
By the way, is there any way to modify the sriHashes at runtime? The fact is I have two cdn for different geo location users. I want to use different cdnURL according to user location. I'm using scripts to duplicate static files and modify cdnURL after build, but for sriHashes, only a replacement is not enough, so is that parsing and adding another set of cdn sriHashes the only solution?
Can you explain your workflow sequence a little bit more? sriHashes are computed once and for all at build time, but once they are injected in the source they will work irrespective of where the file is deployed.
Hi @Shana-AE The issue is that the
/path
component is lost ?yes,
relativeUrl
starts with/
, so/path
is lost
Am I right to assume that we should strip the leading /
from relativeUrl
in that case ?
By the way, is there any way to modify the sriHashes at runtime? The fact is I have two cdn for different geo location users. I want to use different cdnURL according to user location. I'm using scripts to duplicate static files and modify cdnURL after build, but for sriHashes, only a replacement is not enough, so is that parsing and adding another set of cdn sriHashes the only solution?
Can you explain your workflow sequence a little bit more? sriHashes are computed once and for all at build time, but once they are injected in the source they will work irrespective of where the file is deployed.
Thank you for replying!
First of all, we used SPA and we had two cdn urls, one for domestic users, and the other for overseas users. and we upload all the JS and CSS files onto both the CDNs. Let's say one is https://cdn.domestic.com
and the other is https://cdn.overseas.com
And we use nginx to figure out whether a user is domestic or overseas, and serve them different html entries. That says, if user is domestic, serve them a html file that refers to JS files from https://cdn.domestic.com
and when user is overseas serve them another html file that refers to js files hold on https://cdn.overseas.com
As I didn't find a good solution to pass an array to next cdnUrl
or vite base
config to make them build two sets of assets that use different cdnURL. I set the cdnURL
/base
to https://cdn.domestic.com
and after build, I duplicate the files that has https://cdn.domestic.com
string, and replace this cdn string with https://cdn.overseas.com
, and then make nginx points to different entries according to users' geo location. and upload the JS and CSS files onto their related CDN.
And for nuxt and nuxt-security, I found sriHashes
has the string https://cdn.domestic.com
in server/chunks/runtime.mjs
file. I think it is not wise to duplicate this file and make two versions servers runnning, and it should be only one server running. So how can I make https://cdn.overseas.com
files also included in sriHashes
?
Thanks a lot for your kindness!
Hi @Shana-AE The issue is that the
/path
component is lost ?yes,
relativeUrl
starts with/
, so/path
is lost https://github.com/Baroshem/nuxt-security/blob/f7d989c95440a043193bd97325d4a97908f916fc/src/module.ts#L307Am I right to assume that we should strip the leading
/
fromrelativeUrl
in that case ?
I don't know if it has any other effects, but I think yes.
By the way, is there any way to modify the sriHashes at runtime? The fact is I have two cdn for different geo location users. I want to use different cdnURL according to user location. I'm using scripts to duplicate static files and modify cdnURL after build, but for sriHashes, only a replacement is not enough, so is that parsing and adding another set of cdn sriHashes the only solution?
Can you explain your workflow sequence a little bit more? sriHashes are computed once and for all at build time, but once they are injected in the source they will work irrespective of where the file is deployed.
Thank you for replying! First of all, we used SPA and we had two cdn urls, one for domestic users, and the other for overseas users. and we upload all the JS and CSS files onto both the CDNs. Let's say one is
https://cdn.domestic.com
and the other ishttps://cdn.overseas.com
And we use nginx to figure out whether a user is domestic or overseas, and serve them different html entries. That says, if user is domestic, serve them a html file that refers to JS files fromhttps://cdn.domestic.com
and when user is overseas serve them another html file that refers to js files hold onhttps://cdn.overseas.com
As I didn't find a good solution to pass an array to nextcdnUrl
or vitebase
config to make them build two sets of assets that use different cdnURL. I set thecdnURL
/base
tohttps://cdn.domestic.com
and after build, I duplicate the files that hashttps://cdn.domestic.com
string, and replace this cdn string withhttps://cdn.overseas.com
, and then make nginx points to different entries according to users' geo location. and upload the JS and CSS files onto their related CDN. And for nuxt and nuxt-security, I foundsriHashes
has the stringhttps://cdn.domestic.com
inserver/chunks/runtime.mjs
file. I think it is not wise to duplicate this file and make two versions servers runnning, and it should be only one server running. So how can I makehttps://cdn.overseas.com
files also included insriHashes
? Thanks a lot for your kindness!
I suppose you are building a static application (nuxi generate) and not an SSR/hybrid application (nuxi build), right ?
By the way, is there any way to modify the sriHashes at runtime? The fact is I have two cdn for different geo location users. I want to use different cdnURL according to user location. I'm using scripts to duplicate static files and modify cdnURL after build, but for sriHashes, only a replacement is not enough, so is that parsing and adding another set of cdn sriHashes the only solution?
Can you explain your workflow sequence a little bit more? sriHashes are computed once and for all at build time, but once they are injected in the source they will work irrespective of where the file is deployed.
Thank you for replying! First of all, we used SPA and we had two cdn urls, one for domestic users, and the other for overseas users. and we upload all the JS and CSS files onto both the CDNs. Let's say one is
https://cdn.domestic.com
and the other ishttps://cdn.overseas.com
And we use nginx to figure out whether a user is domestic or overseas, and serve them different html entries. That says, if user is domestic, serve them a html file that refers to JS files fromhttps://cdn.domestic.com
and when user is overseas serve them another html file that refers to js files hold onhttps://cdn.overseas.com
As I didn't find a good solution to pass an array to nextcdnUrl
or vitebase
config to make them build two sets of assets that use different cdnURL. I set thecdnURL
/base
tohttps://cdn.domestic.com
and after build, I duplicate the files that hashttps://cdn.domestic.com
string, and replace this cdn string withhttps://cdn.overseas.com
, and then make nginx points to different entries according to users' geo location. and upload the JS and CSS files onto their related CDN. And for nuxt and nuxt-security, I foundsriHashes
has the stringhttps://cdn.domestic.com
inserver/chunks/runtime.mjs
file. I think it is not wise to duplicate this file and make two versions servers runnning, and it should be only one server running. So how can I makehttps://cdn.overseas.com
files also included insriHashes
? Thanks a lot for your kindness!I suppose you are building a static application (nuxi generate) and not an SSR/hybrid application (nuxi build), right ?
No, we use SSR (nuxi build
), we used to use SPA, and here's the problem
Then I'm not sure I get it
cdn.domestic.com
. How do you rewrite domestic to overseas on the fly then ?Sorry to ask so many questions, I think I might have misunderstood your setup
Then I'm not sure I get it
- When the client hits your SSR server, the CDN url in the HTML is always
cdn.domestic.com
. How do you rewrite domestic to overseas on the fly then ?- How is Nginx involved in that process ? If the HTML files are generated on the fly by the SSR server, how can nginx serve a different file for the overseas user ?
Sorry to ask so many questions, I think I might have misunderstood your setup
Anyway, Thank you for your help! Help is always a help :pray: Sorry for not being clear. I also asked at nuxt discord and github disscussion, but got no answer :cry:
overseas/index.html
(which I copied and modified cdn.domestic.com
to cdn.overseas.com
) to serve, and when a domestic user visited, nginx will serve domestic/index.html
So I didn't rewrite the html file on the fly (though it maybe possible to use nginx sub_filter directive to achieve that, I didn't try). This part is about the static thingsI used to think runtimeConfig.cdnURL
can be modified, but I've known I'm wrong, so I'm totally confused how to get the result I want. and how do people handle the similar requirement. like choosing a better cdn on the fly, or provide a high usable service by changing cdn when some cdn is down or just too slow
@Shana-AE let's have this discussion offline on Discord
Version
nuxt-security: v2.0.0 nuxt: v3.13.2
Reproduction Link
https://stackblitz.com/edit/nuxt-starter-iaotaz?file=package.json,nuxt.config.ts,.vscode%2Fsettings.json,.output%2Fserver%2Fchunks%2Fruntime.mjs
Steps to reproduce
nuxt.config.ts
code .output/server/chunks/runtime.mjs
to open the built file since it's not showed in sidebarWhat is Expected?
sriHashes
should consider cdnURL path, and keys should behttps://test/path/<files>
What is actually happening?
sriHashes
ignored cdnURL path, and keys starts withhttps://test/<files>