Express JS not serving few static files, throws 500 internal server error - node.js

When express server is started with SPA application index file and few other static files are loaded and some files throw 500 error
NodeJS server is running, and serving the static files from the correct folder. (This can be confirmed as it loads index.html and some other assets)
As seen from the network tab scripts.2d2e0c1a64a29c086e01.js, jspdf.min.js, favicon are loaded from the same static folder, but other js files are not loaded.
When error files are opened with full link (localhost:3000/main-es2015.b21fb6bfbdb8538cc020.js) these files are also loaded aswell.
The static folder contains the build files from angular 8.
Same issue when tried with nginx reverse proxy config.
Any help is much appreciated. Thank you

I found that the new URL wasn't allowed in the Content Security Policy list, once adding it everything works as expected. Thank you.

I had a similar error -- HTTP 500 when requesting an image from Express -- and corrected it by granting more permission to the static files. When the error was happening, the image file had permissions -rw-rw----. I used sudo chmod 666 public/static/*.jpg to change this to -rw-rw-rw-, and the problem was solved.

Related

Laravel Deployment all routes except / show 404

TLDR
I'm deploying a Laravel application to Directadmin with deployer's recipe. Getting 404 on all routes except /.
What I've tried
Manual Deploy
Initially I created the storage link Laravel requires between app/storage/public and public/storage
ln -sfn /home/myuser/domains/example.com/laravel/storage/app/public/ /home/myuser/domains/example.com/laravel/public/storage
For security I've placed the source files outside of public_html and created symlinks for the contents of public into public_html
/home/myuser/domains/example.com/laravel/
ln -s home/myuser/domains/example.com/laravel/public/* home/myuser/domains/example.com/public_html/
This kept leading me to all sorts of crazy errors during runtime like Whitescreens and route issues even though the deployment cleared cache and routes and followed Laravel deployment steps.
Deployer Script
Switched to Deployer's Laravel recipe and symlinked the each file and folder in current to public_html so I can have subdomains on the same domain. This worked the first 2 deployments round after some coaxing with permissions.
Then had route cache issues causing a symphony closure error. Which I solved by clearing routes and restarting the httpd server.
Next deployment all routes except / show 404.
What I've done this deployment
Reset permissions
npm run prod
php artisan route:clear
php artisan cache:clear
Checked .htaccess
restart httpd
Read most questions on Stackoverflow on 404's and routes [1] [2] which suggest clearing route cache and checking order of routes and typo's in route files.
One thing to note I'm deploying code that works in Dev on Linux PHP8. So there's no issues with the routes files. Deploying to the same Linux distro and same version of PHP.
Most of these steps are part of the deployment script anyway. But somehow Laravel finds a way to break on each deployment (even when it's scripted). Laravel is so temperamental!!
Anyone have an idea what else could be wrong?
[404 Routes Question][1]
[Another 404 Routes question with htaccess][2]
[Laravel Api routes does not work][3]
[1]: https://stackoverflow.com/questions/14160202/laravel-debugging-404-routes
[2]: https://stackoverflow.com/questions/24147460/laravel-all-routes-except-return-404
[3]: https://stackoverflow.com/questions/57400525/laravel-api-routes-doesnt-works-404

Uploading images in meteor js bundle folder on linux server

I'm on Windows and develop meteor project. When i need to upload public media i put it in public folder. After compilation to production on vps server with ubuntu i have tar.gz file which extracting into bundle.
So there is no public folder in a bundle, and all preloaded media placing at web.browser and web.browser.legacy folders in this bundle with access urls like "www.example.com/image.jpg".
I tried upload images into these folders (web.browser and web.browser.legacy) but urls doesn't work with new files. The question is why? And how i can set urls for another folder on server out of bundle and make it public because of all files will be removed after rebundle ?
Meteor-Files package works ok with that. Problem was i couldn't find download urls for uploaded images, answers is here, thx for that.
Default url is "example.com/cdn/storage/Images/image-collection-id/orignal/image-collection-id.extension"

image not displaying on my web page when hosted in lite -server local host..?

when opened the index.html file normally image is displaying
when hosted on lite server the image is not displaying
here is the html code and all the files directory
getting get request 404 for the image file.
here is the bs-config file for the lite-server
is there any solution please...!
I guess if you remove .. from img src, like /src/images/... — it should work.
Paths should be structured keeping the root of your live-server in mind.

How to serve static files with nginx after using npm run build with webpack

after generating a development build with npm run build i get the message saying
"Tip: built files are meant to be served over an HTTP server.
Opening index.html over file:// won't work."
What is the best way to do this with nginx? Currently to test it i am using an npm module called serve.
Also, if i got to my homepage at mydomain.com and search for a user, everything works like it is supposed to, redirecting me to mydomain.com/users/brad but if i then do a url search formydomain.com/users/brad i get a not found error, any help is appreciated!
In my case, when I have to serve static content with nginx, it often looks like :
location /static {
alias $myroot/staticfiles;
}
Also, if you haven't already, read the NginX guide to Serving Static Content.
If your are familiar with the Docker technology i would recommend to use a Docker Nginx Container and add your static content from the Webpack Buildflow to your container (this can be automated with a build server). Have a look at the following Docker Image from Nginx: https://hub.docker.com/_/nginx/.
Otherwise you have to install nginx on your Server where you host your Homepage. For this have a look at your Server OS and reach out to the web for a detailed nginx setup for your server. Without any configurations nginx will serve the static content on Linux-like server from /usr/share/nginx/html
If you only have FTP Access to your server you can transfer your built files via FTP/SFTP to a specific folder e.g /myHomepage and then your static content is server from yourdomain.de/myHompage.

Website images don't load, but other static files do

I have a problem that confuses me since hours. I have a small website with a chat application on an express server. On localhost there is no problem at all. Images load normally, css and js files ok, everything perfect.
But as soon as I push the code online into IBM-Cloud (ex-bluemix), images give me a 404. The rest of the static files do get served though, and the application otherwise works normally.
The file structure looks like this:
--client
--resources
logo.png
--scripts
loginScreen.js
--stylesheets
stylesheet1.css
index.html
--server
app.js
The server starts in app.js and in the code I've put this before initializing the server:
expressApp.use(express.static(path.join(__dirname, "..", "client")));
I had some small problems with filename casing which I detected after building a docker container, but this is resolved and shouldn't be the problem. Any ideas?
The Simple Cloud Foundation Toolchain was registering my commits in github successfully and triggered the auto-build and deploy.
All code changes were pulled normally by the bluemix server. But the filename changes not. So for example the file called Logo.png was renamed to logo.png locally. This change was pushed normally into github. But logging into the bluemix server with ssh revealed that the filename there remained Logo.png.
I had to change the filenames manually by $ mv and now it works.

Resources