Production Node Application Can't Find SVG Files - javascript

In my local development application the svg files show up just fine with the following code (The curly brackets embed Angular.js variables):
<img ng-src="img/servant_{{servant.personality}}.svg" draggable="false">
But when deployed on Heroku, the SVG files result in a 404:
Failed to load resource: the server responded with a status of 404 (Not Found)
The Angular variable is working on the Production site and the image addresses are accurate. So, that's not the problem.
Instead, I think my Node/Express application might not be able to serve SVG files. Perhaps it's a Heroku issue? FYI I'm using the MEAN stack.
Here is the configuration of my public folder:
//Setting the fav icon and static folder
app.use(express.static(config.root + '/public'));
The images are in
public/img
Any thoughts?

Ensure you have the correct mime-type configured to serve SVG files. Some servers simply respond with a 404 if the mime for the requested file type is not set.
image/svg+xml

Related

How can i get input data from a form in node.js?

Working on a weather application in node.js But when i tried to get the input value through document.getElementById to show weather about a specific location it is showing error
i have a file in my views folder where i provide JavaScript file using script tag but even then I am getting error.
error is given below:
GET http://localhost:3000/js/JavaScript.js net::ERR_ABORTED 404 (Not Found)
It is due to the fact that you are not serving a static files in your nodejs server. If you are using express server in your application you have to give the below code in main server js file
app.use(express.static('public')) here public means the folder where you have html, js folder, css folder

socket.io-stream 404 (Not Found)

I have installed socket.io-stream into my node_modules folder which is in my project directory but when I call :
<script type="text/javascript" src="scripts/socket.io-stream.js"></script>
I get these errors in the Console:
localhost/:14 GET http://localhost:3000/socket.io-stream.js 404 (Not Found)
localhost/:1 Refused to execute script from 'http://localhost:3000/socket.io-stream.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
What can I do to resolve this? I have checked to make sure it is in the correct directory and moved it to other directories with no luck.
The file I have this in is an html file not Node js so I cannot use express.
NodeJS is not serving serverside files to the client by default. If it would do so, people could access your whole codebase including configs etc., so that wouldn't be good. Instead, you have to work with the request that comes in at the http module as an event, and answer it with the files content. To do so, you probably want to install the famous Express module (npm install --save express) and use its static file serving:
const Express = require("express");
const app = Express();
app.use(Express.static(__dirname + "/somestaticfolder"));
app.listen(80);
Now just put your file into /somestaticfolder and you are done.
Docs

Windows IIS wwwroot angular javascript serving up .json files not working

The website with index.html is located here
http://www.example.com/index.html
The is using angular/javascript and i'm trying to serve up fake data with .json files
locally I can do this just fine. Its just very simple javascript ... If i have any CORS issues the browser will tell me in developer tools and i just enable a CORS extension in chrome.
Problem:
Go here : http://www.example.com/index.html#/devices
Reason it seems that no data is showing is the obvious message in that it cannot locate this path
http://www.example.com/api/devices.json
What am I doing wrong?
This is where devices.json is located ... under wwwroot
/example.com/wwwroot/api
IIS is serving 404s (not found) for various reasons, to find out what the problem for your request is, without enabled detailed errors, look at the http log files, locate the request in question and find the http sub-status:
192.168.1.200 GET /devices.json - 80 ... 404 3
the number to the right of the 404 is the sub-status, in this case the 3 means: MIME type restriction. IIS by default is not configured to serve status files with a .json extension. You have add a new MIME Type mapping in IIS on the server or site level.
you may not be owner of http://www.example.com/
your IIS settings are wrong. Try to set ist reachable under http://localhost/ or http://127.0.0.1/
You may also modify your host file under system32 folder but it's not recommended.

Serving static files in node.js - 500 internal server error

I'm having a weird issue where our staging server is throwing a 500 error when trying to retrieve css or js assets. We are using broccoli to compile the assets to a distribution directory, so I have ~/dist/assets/app.css (as well as app.js and an img directory). Images seem to be served fine! Only the app.js and app.css files are throwing the 500 error. I've ensured the files definitely exist in their proper places.
We're using express.js and the serve-static module. Code is simply:
serveStatic = require('serve-static');
app.use(serveStatic('dist/assets'));
Then hitting 'http://url.com/assets/app.css' throws the 500.
Hitting 'http://url.com/app.css' WORKS. This seems like it would be okay (since I'm serving dist/assets so the request should be relative to /assets), but this was all working with the /assets prefix on the request a few days ago.
There is no error output produced in the logs anywhere. Stumped on this one.
I just want to make sure I'm not doing anything too dumb.
Have you tried this:
serveStatic = require('serve-static');
app.use(serveStatic('dist'));
serveStatic(root, options)
Create a new middleware function to serve files from within a given
root directory.
Based on that statement, you should expect that using "serveStatic('dist/assets')" will serve the app.css from http://url.com/app.css

NGINX+Bolt CMS - static content calls returning 404 errors

I decided to try out Bolt CMS on my web server, which has happily run several Wordpress sites for a few months now through PHP-FPM.
The site's front end works apparently fine, but the administration section of the site has problems. Every call to static content -- JS, CSS and image files -- results in a 404 (not found) error. What's more, when I look at the NGINX error logs I see that the server tries to access the files from this location:
/usr/share/nginx/
I don't use that directory anywhere in my nginx or bolt configurations! I've done "grep -R '/usr/share' ." in my nginx and bolt configuration directories, with no results returned.
Has anyone had this problem before? where is the /usr/share/nginx/ reference coming from?
Under distributions like RHEL/CentOS (probably others), /usr/share/nginx/ is the location of the default Nginx files. You can grep -R /etc/nginx and that will point you to where.
The usual problem that I encounter (create for my own misery) is that I will create the Nginx virtual host file as something like /etc/nginx/conf.d/example.com instead of /etc/nginx/conf.d/example.com.conf (note the .conf)

Categories

Resources