angular universal on iisnode cant find view error - iis

server side rendering is working good on my local machine
using npm run serve:ssr
i want to upload it to my iis 8 server
this is what i did
building the app on my local machine:
npm run build:ssr
upload the content to my server (iisnode installed)
content folder:
web config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
result: (i notice path is wrong)
what him i missing here ?
Error: Failed to lookup view "index" in views directory "C:\inetpub\wwwroot\universal\dist\browser"
at Function.render (C:\inetpub\wwwroot\universal\server.js:41859:17)
at ServerResponse.render (C:\inetpub\wwwroot\universal\server.js:51402:7)
at C:\inetpub\wwwroot\universal\server.js:113:9
at Layer.handle [as handle_request] (C:\inetpub\wwwroot\universal\server.js:43645:5)
at next (C:\inetpub\wwwroot\universal\server.js:43393:13)
at Route.dispatch (C:\inetpub\wwwroot\universal\server.js:43368:3)
at Layer.handle [as handle_request] (C:\inetpub\wwwroot\universal\server.js:43645:5)
at C:\inetpub\wwwroot\universal\server.js:42868:22
at param (C:\inetpub\wwwroot\universal\server.js:42941:14)
at param (C:\inetpub\wwwroot\universal\server.js:42952:14)

Do you have the following line (in bold) in your server.js file?
app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));

Related

Hosting a sub ASP application in a nodejs express application in azure

Q1) I have my main app built with nodejs express. I have a sub-app made using asp.net and I want to host that as a virtual application within my main app. Is there any way I can do this?
Currently, my nodejs are treating the call https://localhost:5000/mysite1 as a directory and giving a 404 error.
My folder structure looks like...
index.html
server.js
scripts
web.config (*)
----- mysite1
|----- bin
|----- Controllers
|----- Pages
|----- Scripts
|----- web.config (**)
Q2 In the long run, I'd like to take the app to Azure App Services and host it there. The runtime stack would be Node 12 LTS. Is this possible in Azure?
My web.config file for nodejs app.
<?xml version="1.0" encoding="utf-8"?>
<!--
This configuration file is required if iisnode is used to run node processes behind
IIS or IIS Express. For more information, visit:
https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->
<configuration>
<system.webServer>
<!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^cot" />
</rule>
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />
<!--
You can control how Node is hosted within IIS using the following options:
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* debuggingEnabled - controls whether the built-in debugger is enabled
See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
-->
<!--<iisnode watchedFiles="web.config;*.js"/>-->
<staticContent>
<remove fileExtension=".json"/>
<mimeMap fileExtension=".json" mimeType="application/json"/>
</staticContent>
</system.webServer>
</configuration>
Update
Server.js routing
..
....
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/auth', authRouter);
....
..
The virtual application directory structure should look like this.
wwwroot
|----- index.html
|----- server.js
|----- scripts
|----- web.config (*)
mysite1
|----- bin
|----- Controllers
|----- Pages
|----- Scripts
|----- web.config (**)
For more details, you can check my answer in below post.
How to deploy a Flask+React application to Azure Web Service
React.js - How to deploy client and server independently or together?

How to specify a file path in handler tag in web.config

I am trying to run a simple node.js application on Azure cloud.
I basically followed the instruction written in the following websites.
-Creation of Web application-
https://code.visualstudio.com/tutorials/app-service-extension/create-app
-Deployment of Web application-
https://code.visualstudio.com/tutorials/app-service-extension/deploy-app
In order to run it on Azure(IIS), I added web.config and server.js in the root folder as below.
added 2 files
The contents of the files are as follows.
[web.config]
<configuration>
<system.webServer>
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- All URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
[server.js]
The below shows only a part of the codes.
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('./app');
var debug = require('debug')('myexpressapp:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
After deployed to Azure(IIS), the web application successfully ran. However, I would like to use the bin/www file instead of server.js. Actually, I created the server.js file in the root folder by coping the bin/www file.
In order to directly use bin/www, I changed the web.config as follows, but this leads to an error. The browser shows the error;"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." It seems that it cannot find the www file. Am I wrong with how I write the path?
<configuration>
<system.webServer>
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="bin/www" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- All URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="bin/www"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I would appriciate any help.
I was able to solve the problem.
I changed the name of the folder from "bin" to some other name and it worked. I am trying to understand why the name "bin" does not work though...Is it because "bin" is kind of reserved by server and it can not be used? I would appriciate it if someone could let me know any possible reasons...

node js azure error accessing routes

I have a node js application that works fine in my localhost and in AWS. I deployed it to Azure with the following web.config file in the root of the directory:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
</handlers>
<iisnode nodeProcessCountPerApplication="4" />
</system.webServer>
</configuration>
In addition, I have a file iisnode.yml, also at the root of directory, with the line:
nodeProcessCountPerApplication: 4
The root directory contains a file index.js which is the entry point to the application, and it is configured to run an express app on port process.env.PORT || 1337. In package.json, the start command is node index.js.
The application gets deployed, but for every route I try to run I see the following error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Please try to add the rewrite mode in the web.config file, beside the handlers tag under system.webServer tag:
<rewrite>
<rules>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="index.js"/>
</rule>
</rules>
</rewrite>
Any update, please feel free to let me know.

Yeoman angular project in Azure web app

I am using generator to create a angular projects:
https://github.com/yeoman/generator-angular
Loading the website give me this error:
You do not have permission to view this directory or page.
I added iinode web.config:
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="app.js"/>
</rule>
</rules>
</rewrite>
It has a grunt file and doesn't have server.js or app.js as start. How do I go about it?
iisnode will pick app.js or server.js at the root directory (wwwroot) by default. You can override this in web.config. Even you are using grunt, your app should have an entry file somewhere . Say it is at path bin/www/youApp.js, then you can tell iisnode to where to start the app by
<add name="iisnode" path="bin/www/youApp.js" verb="*" modules="iisnode"/>
You can solve it by telling where is the application folder:
Adding a file called .deployment.
Add the below to the .deployment:
[config]
project = app

Can't debug using Azure SDK for Node.js

I am absolutely frustrated by the Azure SDK for years now I have been using it and this problem of outputting errors to the log file still arises:
Application has thrown an uncaught exception and is terminated:
Error: ENOENT, no such file or directory 'C:\DWASFiles\Sites\pazooza\VirtualDirectory0\site\wwwroot\iisnode\RD00155D4313F9-20848-stdout-Tue Mar 26 2013 03:10:56 GMT+0000 (GMT Standard Time).txt'
at Object.openSync (fs.js:240:18)
at Object.writeFileSync (fs.js:628:15)
at SyncWriteStream.<anonymous> (D:\Program Files (x86)\iisnode\interceptor.js:181:20)
at Object.<anonymous> (console.js:25:18)
at IncomingMessage.<anonymous> (C:\DWASFiles\Sites\pazooza\VirtualDirectory0\site\wwwroot\utils\facebook.js:69:21)
at IncomingMessage.emit (events.js:88:20)
at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:130:23)
at CleartextStream.socketOnData [as ondata] (http.js:1288:20)
at CleartextStream._push (tls.js:375:27)
at SecurePair.cycle (tls.js:734:20)
As you see the error occurs because the fs object is trying to find something that is on the c: drive, what is the c: drive pointing to my local machine got to do with the logging system that is suppose to be in the Azure Websites?
And D:\Program Files (x86)\iisnode\interceptor.js
What is that all about shouldn't it be pointing to a resource in the Azure Cloud Websites Instance?
Can anyone from Azure SDK tell me how to make this error go away.
I asked this months and months ago and we thought we had it fixed by now its back again ... very frustrating Microsoft... wtf are you guys doing to make our lives easier?
My other questions on here that lead to this problem:
Webmatrix 2 broken and
Windows Azure Node.js Internal Server Error
My node.js web.config file looks like this:
<configuration>
<system.webServer>
<handlers>
<!-- indicates that the server.js file is a node.js application to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{{REQUEST_URI}}"/>
</rule>
<!-- All other URLs are mapped to the Node.js application entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{{REQUEST_FILENAME}}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
<!-- You can control how Node is hosted within IIS using the following options -->
<iisnode
loggingEnabled="true"
devErrorsEnabled="true"
/>
</system.webServer>
</configuration>
Any help or advice as to why this error shows up when I set logginEnabled="true" would be appreciated.
When I set loggingEnabled to false no errors and the site runs fine, but when its turn on everything is effed up!
Could you file an issue under: https://github.com/windowsazure/iisnode ?
Sounds like this is an issue with IISNode logging ? We may be able to help you there with further details on the issue.
Andre

Resources