Boot: serve non-root directory from classpath in handler + cljs reload - clojure

I have tried to convert a leiningen project to boot: https://github.com/borkdude/lein2boot.
It uses the serve task to serve a handler. The handler offers an API and also serves files. Using the reload task, I want to be able to reload javascript.
I needed to place my html and javascript at the root of a resources directory (in this example "assets"), because the reload task sends changed javascript to the browser using the full resource path (/main.js).
This means I also have to serve the root of my classpath: (resources "/" {:root ""}) in Compojure. The problem with this is that anyone can request any file from my entire classpath: no good.
When I relocate the javascript to assets/public/main.js and serve from the public directory: (resources "/" {:root "public"}), the file can be requested at "/main.js", but the reload task notifies the browser to reload a file from "/public/main.js" which causes a 404.
How can I solve this problem?

It looks like this is being worked on in https://github.com/adzerk-oss/boot-reload/issues/18, but will eventually allow an :asset-path option to provide relative roots.

Related

Uncaught ChunkLoadError: Loading chunk | Module Federation webpack 5 while loading CDN module

Implemented Module Federation for Host and Remote Application.
For the Remote application, federated module is uploaded on a CDN.
While accessing the federated module on localhost, Host application is working fine but while accessing the module using CDN link, getting an error. Error exists during Lazy Loading of the federated module:
Uncaught ChunkLoadError: Loading chunk 531 failed.
Below is my module federation configuration in webpack (Host app):
**new ModuleFederationPlugin({
name: 'common',
filename: 'common',
remotes: {
sampleAppModule: sampleApp#http://CDN-link/remoteEntry.js
// sampleAppModule: sampleApp#http://localhost:8000/remoteEntry.js (this works fine)
},
shared: [sharedDependencies],
})**
Able to see the federated module on CDN link by directly accessing it.
Also, successfully getting 200 status while fetching remoteEntry.js file but error comes when lazy loading the remote module.
This exception can arise when the public path of the remote module is misconfigured, so even if the app can access to the remoteEntry, then it fails to find other chunks because it tries to fetch them from a wrong location. Using code splitting you need to set a Dynamic Public Path on remotes. Webpack can automatically determine the public path when setting an Automatic publicPath. If that is the case, you just need to update the webpack configuration of your remotes like this.
webpack.config.js
module.exports = {
...
output: {
...
publicPath: 'auto',
},
};
If the error appears intermittently, another cause of this exception is misconfigured CDN cache. It's common to configure Webpack using output filenames depending on content hash in combination with long expiration time for cached content on CDN. This configuration optimizes performances because user browsers will cache static assets locally and use those files for subsequent requests.
When using Webpack Module Federation, the remoteEntry.js represents a stable entry point for the remote module. For this reason its name won't change on subsequent builds, even if its content changes. It is updated at every build because it contains a "map" of other files, whose names are dynamically generated with content hash. So, this file should never be cached, allowing the browser to download new files when a deploy occurs.
You can avoid to cache the remoteEntry.js by setting for it a Cache-Control header like Cache-Control: max-age=0 on the server. It's very important to set this header only on the remoteEntry.js file and not setting it as the server default, otherwise every file will be not cached.
Alternatively, if you can invalidate CDN cache for this file, you can set Cache-Control: max-age=0, s-maxage=<time> and invalidate the CDN cache for remoteEntry.js at every deploy. This header allows caching only on shared caches, like the CDN. That way your CDN can serve requests to remote entry, avoiding to request it to the server.

How to access the content of /apple-app-site-association in Ember.js?

I am following https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html
How would I get Ember to serve this url https://www.some-url.com/app-app-site-association
Note, app-app-site-association is a file. Unfortunately, Apple chose not to append an extension to this file.
Ideally, accessing this url should render:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "9F32916B95.foo.bar.baz",
"paths": ["*"]
}
]
}
}
The important think here to understand is that if you want to deliver a static file, may it be your /app-app-site-association or just an image on /something.jpg this has nothing to do with ember.
Ember runs in the browser. So the entire ember routing happens in the browser. Thats why you have to configure your webserver in a way that it serves the index.html file when he does not find a file.
So when you enter example.com/something this will trigger a HTTP GET example.com/something. Your webserver then should check if the file something exists, if yes it should respond with 200 OK and the content of that file.
If if does not find the file something it would normally respond with a 404 NOT FOUND. However when you use an SPA as ember you configure your webserver so it will never respond with 404 NOT FOUND but instead return 200 OK and the body of the index.html. (you can see an example configuration in the ember guides, but this will be different for different webservers)
This then will load your ember app (you've included the .js file in the index.html) and ember will check the current url and start the ember routing. This happens in the browser.
So if something wants to make an HTTP request and get the file app-app-site-association, it does probably not want to get your index.html and then run a browser to let ember do anything. It just wants the file directly from your webserver. So your webserver must directly respond with 200 OK and the content of that file. And it will probably do this as I mentioned above if that file just exists.
Now ember projects have a public folder. If you want to have some files alongside your ember application that should just be served by your webserver this is the right place. Whatever you put in it will just be copied to the dist folder. This means when you then deploy your dist folder you will also deploy the file.
However be careful about your webserver configuration. Because the file has no ending it will probably be served as text/plain. If you want it to be served as application/json you need to configure your webserver accordingly.

<cfajaxproxy> Locked-Down production Lucee

Setting up production lucee box, having issues locating ajax library in lucee server. My browser unable to find ajax library showing 404 error.
I am not sure this is because of firewall or lucee server configuration issue.
My development and staging working fine only having issue in production server.
Request URL: https://example.com/mapping-tag/lucee/core/ajax/JSLoader.cfc?method=get&lib=LuceeAjax
Request Method: GET
Status Code: 404
Remote Address: 201.10.26.29:443
Referrer Policy: no-referrer-when-downgrade
Please advise..
With an Adobe CF server, the JS files related to cfajaxproxy are in the /CFIDE/scripts/ folder. The /CFIDE/ folder is removed from public access when the server is locked down. To allow access to the JS files for the UI and ajax tags, you can specify an alias in CF Admin for that folder.
For example, /cfjs would map to /CFIDE/scripts in CF Amin, so CF will generate that path for cfajaxproxy use. You'd have to create this folder alias in IIS or whatever web server you're using.
If on Lucee, the folder /lucee/core/ is blocked when locked down, there should be a similar solution for that engine.

Setting root path to rails app's root_path in nginx

I've configured a rails app on Digital Ocean (DO) using passenger, nginx and capistrano. Everything is working fine expect that I want to get the application's root_path page to be displayed whenever I go to the website. But that's not the case. I've to keep another page index.html in public directory and set it to root like:
xyz.conf file
root /home/user/apps/xyz/current/public;
I don't want this extra static page to be displayed. It just doesn't look good. Instead I want the application's root page which I specified in routes.rb file like root 'controller#method' to be displayed.
I've tried removing root line or restricting it to just /home/user/apps/xyz/current in .conf file but that just gives a 403 Forbidden error which should be the case.
I've thought a lot but can't think of anything. Anyone out there who had a similar problem and managed to figure it out?
Your nginx root is must be like:
root /home/rails/sample_tasks/public;
Note: path may vary but you need to set path till your app's public folder
then reload you Nginx
service nginx reload

ember cli url not working on server with manual return key (versus link-to)

An ember cli site was deployed onto a server and it works fine. Links via {{link-to}} all work beautifully.
BUT, when a user (me that is) manually enters a url and hits return. then the site is not found.
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
even changing a parameter of a working url (initially navigated to thru link-to)
http://site/start/0/length/30
and simply backspacing, changing the 30 to 20 and hit return
http://site/start/0/length/20
its a no go
localhost:4200 doesn't have this issue.
has anyone observed this vicious behaviour.
i actually need it for a callback redirect for oauth. but then noticed than any manually entered urls dont function.
It is because your server (IIS?) is trying to access the full path requested by your browser (eg /start/0/length/30), and not finding a valid file on disk returns a 404.
So, you need to configure your web server to proxy/rewrite the requests to the proper location. Assuming you are deploying your application in your "root" directory, the proper location is /index.html (the file ember-cli creates).
Unfortunately, I can't help you with IIS, but I can provide you with the proper configuration for nginx:
location / {
try_files $uri $uri/ /index.html;
}
This says "If the requested URI doesn't exist, instead respond with the /index.html file".
When you are using ember server on localhost:4200 you don't have the same problem because it is automatically doing something similar transparently.
If you are serving this up from any web server that isn't the built in Ember, ie non local server, you need to have a wildcard rule that returns your Ember app's index.html file for anything below your websites base url. If you only have your base url return the index.html file, then your webserver is confused by the unrecognized url and thinks it has nothing to return. If your rule, though,
for baseUrl/* returns index.html, your Ember app will then run the correct route hooks to establish the app context
this is a dupe and the question is
How to run emberJS application in IIS?
the easy answer is set locationType: hash in ember-cli's environment.config file (copied from accepted answer)
that will introduce a '#' in the url but doesnt require an IIS change.
var ENV = {
...
locationType: 'hash'
... };