Skip to content

Instantly share code, notes, and snippets.

@benmccallum
Forked from benosman/.deployment
Last active February 28, 2020 09:00
Show Gist options
  • Save benmccallum/226ae1b428157b9d5998a5ba27eadf59 to your computer and use it in GitHub Desktop.
Save benmccallum/226ae1b428157b9d5998a5ba27eadf59 to your computer and use it in GitHub Desktop.
Hosting Nuxt on Azure App Service (iisnode) with custom Git based deployment (kudu)
Previously this gist had a series of files showing a working setup, but,
@burkeholland found a much easier way and demonstrates it here:
https://github.com/burkeholland/nuxt-appservice-windows
Essentially, you'll:
1. add a .deployment file to instruct kudu to run `npm install` for you,
2. leverage npm tasks' `postinstall` hook in package.json to trigger the full nuxt build,
3. add a server.js file in the root that `require`s the default server\index.js file that a nuxt app will already have
Step 3 will be noticed by kudu, which will:
* auto-create you a default web.config for iisnode (if no web.config exists), and
* use that server.js as the entry point, which you've now redirected over to nuxt's default server.js cleanly
Notes:
* For step 3, you'll only have a `server\index.js` if you've chosen a server-side framework in the `npm create nuxt-app xyz` setup.
I had success with express.
* Don't forget to make sure your Azure app is on a high enough node version for both running AND building.
You can now create apps from the portal with a version picker which is nice.
Otherwise you'll wanna configure it with the app setting for runtime and in the .deployment config file for kudu/building.
Kudus to Burke! (pun intended)
@jbbergy
Copy link

jbbergy commented Oct 25, 2019

We have a solution. / point on an empty folder. Then, subfolder work fine.
We also updated Nuxt to the last version (2.10.2).

Thanks,

@julen-folky
Copy link

julen-folky commented Feb 2, 2020

Thanks for the guide! Finally I was able to run my nuxt app on Azure (Windows machine). What it bothers me a bit is the fact I had to add express package. I would like to know how to accomplish the same but without using express. I guess it should be possible, right? Since I was able to develop and run on my local Windows machine.

PS: I skipped the deployment part of the guide, since my first goal is to check the process manually.

@benmccallum
Copy link
Author

benmccallum commented Feb 4, 2020

Hi @julen-folky, unfortunately my knowledge here is very lacking. I checked the Nuxt docs again, and still, IMO, they've never explained well the choice you need to make for the integrated server-side framework. I wouldn't expect them to do a full comparison, but at least a one of two line about each and whether or not you can use the built-in server for most/few cases. Sorry I can't help. Perhaps we should submit an issue to the nuxt repo.

@julen-folky
Copy link

Hi, ben. Where should the issube bet submitted to? Point is the question is not an issue but just a question.

@benmccallum
Copy link
Author

@benmccallum
Copy link
Author

I can post something tomorrow if I get some time.

@julen-folky
Copy link

Thanks ben!

@benmccallum
Copy link
Author

No worries @julen-folky. How's this? Feel free to chip in any thoughts.
https://cmty.app/nuxt/docs/issues/c243 and associated GitHub issue.

@julen-folky
Copy link

Wow! The post perfectly describes the problem. Thanks again!

@benmccallum
Copy link
Author

@julen-folky, no worries. It's easy to describe because I come from the same place and have always wondered the same. I'm a dotnet dev, not a node dev :P Hopefully we get a good answer and some action on it!

@julen-folky
Copy link

I posted on Stackoverflow on the neccesity or not to restart the node process with every deployment.

Sorry if this is not the appropriate thread, I thought it may be of interested for the people following it.

@benmccallum
Copy link
Author

benmccallum commented Feb 26, 2020

I think it's a good question and happy for it to be in this thread. I guess my thinking is that as long as you get your built files inside the wwwroot, then IIS / AppPool doesn't really have an impact, it's just a thin web server layer handling requests and routing them to the node app.

If IIS/AppPool was doing something else, like in-memory caching or the like, depending on the mechanism, you may need to start thinking about an app pool recycle / cache bust, but if the web.config doesn't have anything like that, it's safe to say you'll be fine without one.

@julen-folky
Copy link

Looks like is like you say @benmccallum. Today I checked by chance the page on Azure of the nuxt guide; in the web.config example, by the end there is an explanation about defining a set of files to be watch and recyle the server if they change.

Nevertheless, I would ask for further clarification to a NodeJS/Express expert.

@benmccallum
Copy link
Author

Good spot! I guess if you were doing in-memory caching (inside your node app of config files or something) then it makes sense that you'd need to configure watching of those files to restart the app. Since they haven't indicated anything in particular I'd say that nuxt itself doesn't do anything like this or can handle those kinds of filesystem changes. Static assets (those picked up by the static rewrite rule) will cache bust themselves as part of standard IIS if you had static asset caching I imagine (which isn't demonstrated here but should probably be turned on).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment