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 react *.js to the project, instad of load from external - CSP support #84

Closed
GAS85 opened this issue Jul 8, 2022 · 4 comments
Closed

Comments

@GAS85
Copy link

GAS85 commented Jul 8, 2022

Hey, like your product much.
I have server with CSP enabled and opcache UI will not be opened without whitelisting of unpkg.com.
Is this possible to add js files to the project so that it will be loaded from the same FQDN as UI?
Or is there is an easy way to re-configure it locally?
grafik

@amnuts
Copy link
Owner

amnuts commented Jul 13, 2022

Hi @GAS85,

One of the things I've always tried to do is keep it as only requiring one file. Even though there are multiple files in the repo, once it's built it's all in the one index.php, so I'm not keep on having separate js files. Ideally I'd not want to embed those js files into the finished result, either, as I'll always have to maintain the current version rather than letting unpkg.com do it for me.

There's nothing stopping you doing that, though. With a couple small tweaks to the template you should be able to do what you need.

For example, what you could possibly do is fork the repo and in your fork add the js files to the top-level. Then update build/template.phps so that the three script tags point to your local copies. Then when you build the index.php file (instructions at https://github.com/amnuts/opcache-gui#changing-the-look) you'll use your local files.

This should also keep your changes to a minimum, so that whenever I make changes to the origin you can replay your changes on top of them pretty easily.

As I'm writing this, I'm thinking that it shouldn't be too difficult for me to add that functionality into the little build script... 🤔 I'm a little busy for the next week or two, but I'll see if I can come up with anything. In the meantime, give the idea a go yourself and see if it helps you out.

@GAS85
Copy link
Author

GAS85 commented Jul 15, 2022

Basically I solved it by simple script - externalJSDownloader.sh, but somehow github is slow now and I could not create any commit or MR.

It should be run once, will download JSs and replace all links directly in index.php to the relative local one. No rebuild required. It should be executed under web server user, otherwise file ownership must be updated afterwards.

#!/bin/bash
 
# By Georgiy Sitnikov.
#
# AS-IS without any warranty

file="index.php"

getJSLinks="$(grep "script src" $file | awk -F'["]' '{ print $2 }')"

echo "Backup $file to $file.origin"
cp $file $file.origin

while read JSLinks; do

	JSName="$(echo $JSLinks | awk -F'[/]' '{ print $NF }')"
	echo "Downloading $JSName from https:$JSLinks"
	curl -fsSL -m 10 https:$JSLinks -o $JSName

	echo "Replacing $JSLinks with $JSName in $file"
	sed -i "s,$JSLinks,$JSName," "$file"

done <<< "$getJSLinks" # Read from variable

echo "Done."
exit 0

@amnuts
Copy link
Owner

amnuts commented Jul 16, 2022

Nice one! I took a basically the same approach, but wanted to keep it all the PHP that was already there, so am doing it in the build.php file. I think for the most part, people wouldn't need to change it anyway, but if needs be it can be run with php build.php -l and it essentially does the same thing your great bash script does.

Currently in branch working/3.4.0, but probably going to be merged into master soon.

@amnuts
Copy link
Owner

amnuts commented Aug 2, 2022

Now merged into master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants