Hosting API built using loopback.io for Azure using IISNode

So I'm trying something undocumented. I have built a simple rest API using loopback.io in nodejs and now I want to host it on azure websites. I rejected https://github.com/strongloop/loopback-getting-started and followed the steps outlined at https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-develop-deploy -mac /

I was able to push the files and get the deployment, but I'm not sure how IISNode will launch the application because server.js is under /server/server.js. IISNode doesn't find server.js in root and doesn't create web.config.

I ran into this Point iisnode in the server.js file nested in a folder on the iis site , but couldn't get it to work locally. This is what I have tried

  • create server.js at root level with content

require(__dirname + '\\server\\server.js')();
      

Run codeHide result


  • noticed that loopback starts the application with "node". I assumed it was using the main define module in packages.json, so I also changed the location of the main module from "/server/server.js" to "server". JS "

{
  "name": "Sample",
  "version": "1.0.0",
  "main": "server.js",
  "scripts": {
    "pretest": "jshint ."
  },
  "dependencies": {
    "compression": "^1.0.3",
    "cors": "^2.5.2",
    "errorhandler": "^1.1.1",
    "loopback": "^2.14.0",
    "loopback-boot": "^2.6.5",
    "loopback-datasource-juggler": "^2.19.0",
    "serve-favicon": "^2.0.1"
  },
  "optionalDependencies": {
    "loopback-explorer": "^1.1.0"
  },
  "devDependencies": {
    "jshint": "^2.5.6"
  },
  "repository": {
    "type": "",
    "url": ""
  },
  "description": "Sample"
}
      

Run codeHide result


after these two changes when i run "node". I encountered the following error:

C:\Users\anirudh\Documents\GitHub\Sample\node_modules\loopback\node_modules\express\lib\router\index.js:138
  debug('dispatching %s %s', req.method, req.url);
                                ^
TypeError: Cannot read property 'method' of undefined
    at Function.handle (C:\Users\anirudh\Documents\GitHub\Sample\node_modules\loopback\node_modules\express\lib\router\index.js:138:33)
    at EventEmitter.handle (C:\Users\anirudh\Documents\GitHub\Sample\node_modules\loopback\node_modules\express\lib\application.js:173:10)
    at app (C:\Users\anirudh\Documents\GitHub\Sample\node_modules\loopback\node_modules\express\lib\express.js:38:9)
    at Object.<anonymous> (C:\Users\anirudh\Documents\GitHub\Sample\server.js:1:105)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)

      

I'm not sure what I'm missing, any help would be appreciated

+3


source to share


3 answers


I think the best way is to create a .deployment file at the root of your project that points to Kudu (which is the SCM (Service Control Manager) that Azure uses to deploy your site, figure out what it is, its state, and make it work with IIS) to the correct directory in the deployment files.

It's easy. Just create a new text file at the root of your directory called .deployment

and place it in it ...



[config]
project = server

      

This will tell the deployment script to view the server folder as the site root. Hope it works for you!

+3


source


Node detection

If you're scrolling through the portal interface for websites, you may have noticed that there is an option to enable PHP, but not node. Instead, the website looks for the presence of an app.js or server.js file in your deployment and will include the node feature if any of those files are present.

When an app.js or server.js file is found for deployment, a web.config file will be generated containing the configuration information required by iisnode. Note that this file is not added to the remote git repository, so if you pull from the git website repository, you will not get this file. You can use ftp to connect to the server and find it in the wwwroot directory that contains your website.

Npm server side

So what happens if you deploy a project that does not contain a node_modules folder? Well, if you have a package.json file that lists the required modules, Windows Azure will actually run npm on your website and try to install those modules. You can see this by creating a new express site using the express command and then deploying it to the website using git. You will see the expected output from git, but then you will see output similar to the following:



remote: New deployment received.
remote: Updating branch 'master'.
remote: Preparing deployment for commit id '3f69628e8c'.
remote: Preparing files for deployment.
remote: Running NPM.
remote: npm http GET http://registry.npmjs.org/jade
remote: npm http GET http://registry.npmjs.org/express/2.5.8
remote: npm http 200 http://registry.npmjs.org/express/2.5.8
remote: npm http GET http://registry.npmjs.org/express/-/express-2.5.8.tgz
remote: npm http 200 http://registry.npmjs.org/express/-/express-2.5.8.tgz
remote: npm http 200 http://registry.npmjs.org/jade
remote: npm http GET http://registry.npmjs.org/jade/-/jade-0.26.1.tgz
remote: npm http 200 http://registry.npmjs.org/jade/-/jade-0.26.1.tgz
remote: npm WARN excluding symbolic link lib\index.js -> jade.js
remote: npm http GET http://registry.npmjs.org/mime/1.2.4
remote: npm http GET http://registry.npmjs.org/qs
remote: npm http GET http://registry.npmjs.org/mkdirp/0.3.0
remote: npm http GET http://registry.npmjs.org/connect
remote: npm http 200 http://registry.npmjs.org/mime/1.2.4
remote: npm http GET http://registry.npmjs.org/commander/0.5.2
remote: npm http GET http://registry.npmjs.org/mime/-/mime-1.2.4.tgz
remote: npm http 200 http://registry.npmjs.org/qs
remote: npm http 200 http://registry.npmjs.org/mkdirp/0.3.0
remote: npm http GET http://registry.npmjs.org/qs/-/qs-0.4.2.tgz
remote: npm http GET http://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz
remote: npm http 200 http://registry.npmjs.org/connect
remote: npm http GET http://registry.npmjs.org/connect/-/connect-1.8.7.tgz
remote: npm http 200 http://registry.npmjs.org/connect/-/connect-1.8.7.tgz
remote: npm http 200 http://registry.npmjs.org/qs/-/qs-0.4.2.tgz
remote: npm http 200 http://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz
remote: npm http 200 http://registry.npmjs.org/mime/-/mime-1.2.4.tgz
remote: npm http 200 http://registry.npmjs.org/commander/0.5.2
remote: npm http GET http://registry.npmjs.org/commander/-/commander-0.5.2.tgz
remote: npm http 200 http://registry.npmjs.org/commander/-/commander-0.5.2.tgz
remote: npm http GET http://registry.npmjs.org/formidable
remote: npm http 200 http://registry.npmjs.org/formidable
remote: npm http GET http://registry.npmjs.org/formidable/-/formidable-1.0.11.tgz
remote: npm http 200 http://registry.npmjs.org/formidable/-/formidable-1.0.11.tgz
remote: jade@0.26.1 ./node_modules/jade
remote: โ”œโ”€โ”€ commander@0.5.2
remote: โ””โ”€โ”€ mkdirp@0.3.0
remote:
remote: express@2.5.8 ./node_modules/express
remote: โ”œโ”€โ”€ mime@1.2.4
remote: โ”œโ”€โ”€ qs@0.4.2
remote: โ”œโ”€โ”€ mkdirp@0.3.0
remote: โ””โ”€โ”€ connect@1.8.7 (formidable@1.0.11)
remote: SetConsoleTitleW: The operation completed successfully.
remote:
remote: Deploying Web.config to enable Node.js activation.
remote: Deployment successful.
      

Run codeHide result


One thing to look for are modules that rely on node-gyp to compile their own bits at install time. The website environment lacks things available from node-gyp (like Python), so node-gyp will fail. The workaround is to install and create a custom module on a windows system and then deploy the node_modules folder as part of the git deployment. So the compiled bits already exist.

So if you have a git repo and node is running on the website. go and install loopback and then check your code again and you will see its action

Some general node guidelines from azure https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-develop-deploy-mac/

A bit old but still valid http://blogs.msdn.com/b/silverlining/archive/2012/06/14/windows-azure-websites-node-js.aspx

cock noose big brother strong https://azure.microsoft.com/en-us/marketplace/partners/nodejsapi/node-js-api/#starter

+1


source


Loopback server application will not start unless called with

node server / server.js

However, IIS calls it from a different file:

required ('server / server.js')

which means your loopback server won't start.

Here's the route to fix: https://github.com/masonkmeyer/loopback-azure

The error node .

is that you were doing unnecessary moves to the server.js file

0


source







All Articles