I got a node.js express application and i need to make it run on my local IIS server so i can send valid http requests to it and work with the responses.
I am using win 10 and IIS 10.
I followed the different guides about working with iisnode in order to use node.js application on IIS.
https://github.com/tjanczuk/iisnode
I also managed to run the tests, so the iisnode is installed, valid and is working together with my IIS.
The "built-in" test is being executed under the default web site which comes with IIS, it creates a new application under it from which there is a working access to the different examples.
My problem is that i am still lacking some information about how to setup my own node.js app on IIS since this information seems to be lacking.
And later on how to overcome issues with invalid http requests.
HTTP status: 500
HTTP subStatus: 1001
HTTP reason: Internal Server Error
I would advice to follow the next guide,
https://harveywilliams.net/blog/installing-iisnode
combined with the official github page of iisnode,
it has all the details about making a simple express node.js app working from scratch with iisnode on IIS.
I would advice to test each part before moving on to the next and once done testing to start first from a minimalistic and simple app of your own and once everything is working build it up from there.
P.S. The reason for this error for me was bad naming when i used express.routing
step 1 :- Install Node js
step 2 :- Install IISNode :- from here
then root folder structure like below.
iisnode folder contains log file and index file.
step 3 :- create angular server side build so it will creates browser and server folder. add them in dist folder as shown in below.
Related
I have a nodejs application as the frontend and built my api in apsnetcore webapi. I'd like to run the api in the same domain i.e. /api. However I'm presented with runtime environment question when creating app service where I have to choose between dotnetcore and node. Anyone know how to get this to work?
Looks like you can from the link here if you
"tweak URL Rewrite rules in web.config so that specific URLs are being handled by IISNode and the other ones by ASP.NET."
I've created a node webapp with express-generator, this app works great on localhost.
But as soon as i move my app to the server and surf the domain, it shows the content of the app.js file instead of executing it, i've tried to reproduce this issue on localhost without success.
I've also checked the configuration of the web server, looks good so far.
If i run the app on localhost, the app.js file gets executed without any problems, but on the webserver the file content is shown only and nothing executes.
This only happens with the app.js file, any other file of the app works fine, views are rendered and routes are working.
I'm grateful for any help!
Some additional information:
OS: Windows Server 2016 Datecenter
Node 12
Node app deployed via Plesk Obsidian
This is solved, it looks like this is a problem with iisnode since the app works as it should when it runs as a service
Here's the only error message I've been able to find, from an error file in /LogFiles/W3SVC1180911273:
ModuleName iisnode
Notification EXECUTE_REQUEST_HANDLER
HttpStatus 500
HttpReason Internal Server Error
HttpSubStatus 1001
ErrorCode The system cannot find the file specified.
(0x2)
I have a project I've been developing locally that I'm trying to now host to Azure. It's a Node project using socket.io, Webpack, and Typescript for the server-side and client-side JS. I haven't been able to get it working. Navigating to the site gives me a "This page isn’t working" 500 error.
I've created a custom deploy.cmd file that runs webpack and compiles my typescript. I've created an iisnode.yml file to make sure loggingEnabled: true is set. I've turned on Web Sockets in azure, and ensured that <webSocket enabled="false" /> is set in my site's generated web.config, though I don't think sockets are the issue.
I also made sure that the express app is listening on process.env.PORT so that it uses the named pipe from Azure.
I use a site log tail to view the node logs and when I first navigate to the site after starting it, I see my node server start up successfully, without errors, and begin running. But the request always fails, multiple times in a row.
I can't find anywhere that it says what the actual file is that it can't find.
I previously had some ENOENT: no such file or directory errors thrown by node, and those showed up in my /site/LogFiles/Application/logging-errors.txt file, as well as my streaming logs. So the issue isn't with Node, it's with IISNode. And I can't figure out where to get more details about what's failing.
I'd greatly appreciate anyone being able to help me figure this out.
I am trying to host a new ASP.NET 5 WebAPI project in IIS, and I am using the ASP.NET 5 RC 1 runtime. The project that I am using is the standard generated template for a new ASP.NET 5 WebAPI project. (No code changes.)
I have successfully published the project using the command line, and I can get the application to work in a new web site using a specific port, such as localhost:12345. For example, accessing localhost:12345/api/values returns the values.json data from the project template.
However, when I try to use an IIS Application folder for the project, I am getting a 404 error. In other words, localhost:12345/WebApi1/api/values returns a 404 error. But I can see Kestrel running on a random port in the Event Viewer, and if I access the data on that port, I do get values.json back, so I know Kestrel is running.
Is there something special that needs to be done to get an ASP.NET 5 WebAPI project working in an IIS Application folder under a web site?
Side note: if I use --server.urls to set a port for Kestrel, it's running both on the requested port and the random port logged in the Event Viewer. (So it's actually available from Kestrel from 2 URLs, not the single one configured by --server.urls.)
Kiran Challa's link above indeed does fix the problem. Put this in your Configure method in Startup.cs
app.Map("/IISApplicationFolderName", (myAppPath) => this.ConfigureApp(myAppPath, env, loggerFactory));
where IISApplicationFolderName is the name of the IIS application folder that you want to host under. The rest of the configuration code moves to the new method ConfigureApp, since you're delegating your configuration to that method.
This also looks to be a temporary patch until ASP.NET 5 RC2 is released.
I'm not sure what I'm missing here, so hopefully someone can help me out. I'm working on a project where we're using Node and in the Run/Edit configurations I've down the following:
Node interpreter: This is the path to the node.exe file
which I checked out from Subversion
Working directory: this is where the "app.js" file is, this is the
path that from the command line you type node app.js and it starts the server
JavaScript file: app.js This is the name of the file that actually creates the server
Now from the main nav bar when I do Run / Run my server the box at the bottom pops up and tells me that Express server is listening on port 3000. Cool.
I can navigate to localhost:3000/myPage.html and I can get to the page just fine.
I added as JSON file to the same directory on my hard drive that myPage.html is in, and I can navigate to that as well by localhost:3000/largeTestData.json.
So the server is up and running and serving file as it should. My problem is that in my Webstorm project, I want to make an AJAX request to that largeTestData file. I do so using jQuery like:
var data = $.get('localhost:3000/largeTestData.json');
data.done(function(data){
console.log('here is your data');
cnosole.log(data);
})
When I do that I get the error (in Chrome)
XMLHttpRequest cannot load localhost:3000/largeTestData.json. Cross origin requests are only supported for HTTP.
and so I look at the URL and I'm seeing:
http://localhost:63342/
Obviously Webstorm has started the server correctly, but when I view an HTML file, it's not using that server (which, of course is why I'm getting the CORS error.
There's some fundamental stuff here which I'm obviously not getting. I need my IDE to deploy to the Web server that it started up, but it's not doing that. Please, someone give me a once over on all the technologies that I'm missing out on here.
WebStrom didn't start your node.js server, but serves static pages by its own internal HTTP server which doesn't know anything about node.js and Express.
The main problem:
When you start your node.js server, it's serving JSON files on port 3000. If you open an HTML-page with the little menu in WebStorm (where you can choose the browser), WebStorm opens the browser with an URL pointing to its own internal webserver running on a different port (e.g. 63342). JavaScript security prohibits loading data from a different host/port Same-origin policy.
It's not WebStorm's fault and you need a solution for this problem in production or you can't go live.
General Solution:
Either you have to ensure that HTML pages and JSON data come from the same host+port, or you can circumnavigate with (a) setting server-side headers ('Access-Control-Allow-Origin: *') as #lena suggested, or (b) using JSONP. Below you find some thoughts using nginx as a reverse proxy so from browser's point of view all requests go to the same host+proxy. It's a very common solution, but as mentioned above, there are other options.
Primitive solution:
Don't use WebStorm to open your browser. Load the page from http://localhost:3000/ and change the URL of the REST resource to $.get('/largeTestData.json'). You'll miss some comfort from your IDE, but you can immediately see that your program is working.
Comfortable solution:
As #lena suggested, there is a way to configure your Express/node.js as a server known to WebStorm. I haven't tried it, but I suppose you can then just press the Run-button and maybe the node.js plugin in WebStorm is as intelligent to know the static-maps in Express and know how to map an HTML-file to a web application URL and open the page in the browser with the URL served by your node.js application. (I'd be surprised once again if this really works magically, but maybe you can configure a mapping from files to URLs manually, I don't know.)
Dirty solution
With some options you can disable security checks, at least in Google Chrome. Then it's possible to load JSON data from a different port than your HTML page. I wouldn't recommend using these options (just my opinion).
Additional Hints
If you do more than just playing around with node.js and some UI fun and you have to serve your application "production-ready", then have a look at nginx to serve your static files and reverse proxy node.js requests from there. I'm using this setup even for development and it works like a charm.
Of course node.js / Express is able to serve static files as well, but IMO placing something like nginx in front of node.js (clustered) bring a bunch of advantages for production sites, e.g. load-balancing, ssl-offloading, avoid JSONP, in many cases performance, easier deployment updates, availability.
To get your code working, just change the URL in $.get() to full URL (including protocol):
var data = $.get('http://localhost:3000/phones.json');
In Webstorm 2016.3 (and probably earlier) there is now another option. Under the Configuration Settings for NodeJS runs, one can manually set the page and port to be loaded via Webstorm's "Browser/Live Edit" settings.
See the screenshot below for settings one can change.