Create-React-App absolute paths to JS and CSS in prod build - url

I'm using create-react-app and in prod I'd like to serve the JS and CSS and other static assets on s3, but serve the index.html file from another location. However, the URLs in the built files are all relative paths.
Is there a way (without ejecting) to use absolute URLs in the production build?

Apparently this is achievable with the PUBLIC_URL environment variable. I was under the impression this variable was intended to be used if the React app would be living in a sub-directory, in order to fix client side routing. However, by adding:
PUBLIC_URL=https://<my-s3-bucket_url>
The URLs in all files become absolute URLs instead of relative URLs.

Related

Issue with path using twig templates

I'm currently resuming an existing project and I'm facing path issues with a twig (the project use no framework for twig templates). I'm trying to run this project locally with wampserver. I defined my new base-path so that wamp can run it but it can't redirect me correctly when I'm using forms for example. It can't also find paths to images.
For example, I can try to connect using the URL:
localhost/autres/admin_LP/admin
but when I submit I'm redirected to:
localhost/admin/dashboard
instead of:
localhost/autres/admin_LP/admin/dashboard
In other terms, the part "/autres/admin_LP" is missing.
It's the same issue for images, the path is wrong:
incorrect path for image
The image path should be:
localhost/autres/admin_LP/Web/template/View/Easylife.png
instead of:
localhost/Web/template/View/Easylife.png
Apparently, I correctly modified the .htaccess since I'm directed towards the connection page. But since the project uses twig templates, I think I missed some twig configuration so that it can find the right path.
I'm a rookie with twig templates so if you have any clue about how I can properly run my project locally, I'm more than interested!

How to serve some static files of a certain file type, but not others?

My ASP.NET MVC project's root directory contains some typical static files, like robots.txt, manifest.json, browserconfig.xml, etc. If I'm not mistaken, each of these examples I listed should be able to be served with no involvement from MVC via GET requests to the root directory (i.e. mysite.com/manifest.json — if that's not true, please let me know).
I know from this answer that I can configure this behavior per file type in the Web.config. My question is, what if there are other .json files in my root directory that I don't want to serve, like compilerconfig.json or bundleconfig.json (both files generated by IDE tools)? What's the best way for the application to be able to serve some files of type X, but not others?
You can always ignore them via routes:
routes.IgnoreRoute("{somefilename}.json");
Another alternative would be to move the files you don't want to be served to another folder and add a web.config file to it to manage what gets served (or doesn't).
I am sure there are other ways. Modules come to mind...

Static content delivery vs dynamic in WildFly

My application ear is bundled with static resources like js, css, images, etc and was serving js files at URI app/scripts. These requests were passing through filters in the application. Now I configured WildFly to serve static contents like images, js and css. It is served at path app/scripts for js. Since both have same URI which one will be working now? It looks like static content is getting precedence because I noticed that now request are not passing through filters. Which method is better option to improve performance?
Hi Make your static contents as a separate deployment. And Create a folder named "MyContents.war" in deployment folder of your Wildfly and keep all your scripts, css what ever inside that folder, add the following settings in your standalone.xml file inside <server> tag.
<deployments>
<deployment name="MyContents.war" runtime-name="MyContents.war">
<fs-archive path="deployments\MyContents.war" relative-to="jboss.server.base.dir"/>
</deployment>
</deployments>
Now to access any resource like a script file for example scripts.js
http://<yourhost>:<port>/MyContents/scripts/scripts.js
Hope this helpful for you.

Favicon with Meteor?

I'm trying to load a favicon into my Meteor project but I can't get it to work. I tried using this tutorial but when I put the mentioned reference in the of my HTML nothing happened. Also what do they mean by /public directory? I don't have a /public directory, should I just put my favicon.ico in the root directory?
The public directory doesn't exist by default - you just need to create it. Meteor uses the public directory in the root of your app to serve plain files rather than bundling them in the app. In order for a <link rel="icon"> tag to work, it needs to point to a file that exists in public. Note that the URL to the icon will not contain the path "public/" - files in public are served as if they were at the root of your web server.
A new Meteor app doesn't include any folders except the required .meteor directory. However, it will treat folders named public, private, client, server, and lib specially. You can also create more arbitrarily named directories. This affords you a lot of control over the exact structure of your app. Read about the Meteor directory structure in the Documentation:
Lastly, the Meteor server will serve any files under the public directory, just like in a Rails or Django project. This is the place for images, favicon.ico, robots.txt, and anything else.
Create client/header.html: <head><link rel='icon' href='/favicon.ico'></head>
Put you favicon.ico into /public folder.
Start server, open your browser and see the result.

MVC 4 bundled scripts does not reflect my changes to the script files

I have a MVC 4 application in .NET 4.0. My web hosting provider (network solutions) has virtual directories setup so I can't use the default bundling behavior (I think).
In my _Layout view I have this line:
#Scripts.Render("~/bundles/dd-d2")
In BundleConfig.cs I have
bundles.Add(new ScriptBundle("~/bundles/dd-d2").Include(
"~/Scripts/dd-d2.js"));
And everything works fine when I run in visual studio. But when i upload to my web hosting, The file is not found because it appends the virtual folder in front of the bundle path.
instead of /bundles/dd-d2?v=BlahBlah, I get /ROOT_FOLDER/bundles/dd-d2?v=BlahBlah
I fixed this issue by adding this to my line in the _Layout file
#Scripts.Render(Url.Content("~/bundles/dd-d2"))
The Url.Content helper converts the virtual path into an app absolute path and it finds my bundled script files.
Now, the problem I am having with that approach is, if I make a change to the javascript file, it is NOT reflected in the outputted bundled script file. It always has the old information in it even when I upload it to my web hosting. Is this file cached somewhere? Is there a better way of doing this? I would like to take advantage of the minification of my script files by using bundling.
if I do it this way, it does work
<script src="#Url.Content("~/Scripts/dd-d2.js")" type="text/javascript"></script>
But then my script is not minified.

Resources