Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for external server for serving the static assets #6311

Closed
wants to merge 3 commits into from

Conversation

tardyp
Copy link

@tardyp tardyp commented Oct 18, 2016

Implementation for #6307

There is still the need to setup CORS in the static server as system.js is fetching
the scripts via xhr.

Using scriptLoad: true will not work here (yet) as it needs to have much more metadata.

This also adds a better approach for cacheBusting (using the git commit id, instead of Date.now())

@CLAassistant
Copy link

CLAassistant commented Oct 18, 2016

CLA assistant check
All committers have signed the CLA.

@torkelo
Copy link
Member

torkelo commented Oct 18, 2016

cache busting is handled by the javascript file is minified and revisioned (gets a hash in it's name)

@tardyp
Copy link
Author

tardyp commented Oct 18, 2016

@torkelo thanks, this wasn't clear for me, as I am building from source for 32bit

make build will not generate the production JS, I had to dig into the grunt file to finally find the grunt release task.

I uploaded a new version without the cacheBusting fix.
It is now working on my home server with static files served by another ISP.

System.config({
defaultJSExtenions: true,
baseURL: 'public',
baseURL: getBaseURL(),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this change is necessary.
Do the plugin system uses this? in this case this is necessary. If its only the config for the boot.js generation, then I will remove the change.
Please advise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot change baseURL in system.conf some things are loaded async (plugins and some sections)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont we want to load those things from the static server? In this case, we need to have system.conf point to the static server.

So for the build, we need it to point to local filesystem 'public', but for the production, we need it to point to the static server.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non core plugins are fetched via a special route public/plugins/ so this approach wont work.

There is still the need to setup CORS in the static server as system.js is fetching
the scripts via xhr.

Using scriptLoad: true will not work here (yet) as it needs to have much more metadata.
@tardyp
Copy link
Author

tardyp commented Oct 19, 2016

@torkelo is there anything I need to do for this PR to be merged?
Please let me know.

For optimization you can put those files on a host optimized for serving static
files (like a CDN or S3 like server).

> **Note** You will need to setup CORS headers on your static server to make this work
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit confused about line :) the CORS headers would be needed on the grafana-server http api, not the static server

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
Because system.js loads its JS using XHR, then the static server must have cors configured to enable XHR from the grafana server URL

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, yea your right

@@ -172,7 +173,7 @@ func init() {
logger = log.New("settings")
}

func parseAppUrlAndSubUrl(section *ini.Section) (string, string) {
func parseAppUrlAndSubUrl(section *ini.Section) (string, string, string) {
Copy link
Member

@torkelo torkelo Oct 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems a bit strange, why mingle the public url parsing with the static url?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for generating the default value, which is based on the public_url

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but seems strange to have that in this function, or am I missing something?

- remove setup of static_url in system.conf.js
  after discussion, this is not straightforward to load the plugins from a static server
- remove references to CORS.
  As system.js will not load anything anymore in production mode, there is no need to setup cors.
- mention that the plugins are still served by the main server
- refactor the setting code to parse static_url apart from the AppUrl
@tardyp
Copy link
Author

tardyp commented Oct 20, 2016

I updated the code to address the review comments

@torkelo
Copy link
Member

torkelo commented Oct 21, 2016

Have you tested to install external plugins, does it work?

1 similar comment
@torkelo
Copy link
Member

torkelo commented Nov 1, 2016

Have you tested to install external plugins, does it work?

@tardyp
Copy link
Author

tardyp commented Nov 1, 2016

@torkelo I have not yet tested the installed plugin

@torkelo
Copy link
Member

torkelo commented Dec 6, 2016

created feature request for this issue, #6844

Closing this for now to gauge interest.

@torkelo torkelo closed this Dec 6, 2016
@Gauravshah
Copy link
Contributor

interesting, would help speed up load times.

@ying-jeanne ying-jeanne added the pr/external This PR is from external contributor label Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/external This PR is from external contributor type/feature-request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants