Giter Site home page Giter Site logo

ertugrulaktepe / nextjs-server-azuresiteextension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mrcollective/nextjs-server-azuresiteextension

0.0 0.0 0.0 15 KB

An Azure Site Extension for hosting Next.js apps built using `next build` where you just need to deploy the .next folder.

License: MIT License

JavaScript 33.82% PowerShell 55.99% Batchfile 10.19%

nextjs-server-azuresiteextension's Introduction

Next.js Server Azure Site Extension

An Azure Site Extension for hosting Next.js apps built using next build where you just need to deploy the .next folder.

All you need to do to deploy a Next.js app to Azure App Service is:

  1. Install the nextjs-server site extension (either via the Portal or programmatically via ARM)
  2. Run next build for your site (e.g. on a build server)
  3. Grab the .next folder (e.g. as a build artifact)
  4. Deploy the .next folder to your website

Note: If using MsDeploy and you set the option to delete files on the destination that aren't on the source then you will need to set skip rules for Web.config, server.js, npm-shrinkwrap.json, package.json, node_modules.

What the extension does

When installed it will add the following files to your wwwroot folder:

When installed, it will then run npm install in your wwwroot folder - this can take a few minutes, but only needs to run once when installing the extension (or when upgrading the extension in the future).

The packages installed will be the following (along with their dependencies as per the npm shrinkwrap file):

  • "express": "^4.16.2",
  • "next": "^4.2.3",
  • "react": "^16.2.0",
  • "react-dom": "^16.2.0"

Motivation

When deploying a Next.js app via VSTS RM the Continuous Delivery feature means that Kudu doesn't run it's smarts that will automatically set up the site with the web.config file for Node.js deployments and run npm install for you.

Thus to get your app working you need to deploy all of the files required to run the app, but this includes the node_modules folder with express, next, react and react-dom and all of their dependencies, which is over 12k files and this seriously slows down the build and deployment pipeline. In reality you only need these files in the site once so packaging them with every build and deploy doesn't make much sense.

This site extension allows you to delegate the installation of these files to the platform infrastructure. You can programmatically install the extension via ARM (i.e. infrastructure as code) and then all you need to do to get your Next.js app running on Azure is to package and deploy the resultant .next folder after running next build.

Todo

  1. Look at adding a web job that runs npm install asynchronously to site extension install (since currently the extension times out waiting after 60s) and drops a file on the filesystem to indicate when the install is done. Potentially change server.js to detect when that file isn't present and show the user a nice message indicating the server is starting up still.
  2. Release to the site extensions site so it can be used in Azure (currently it's there but the single package has been unlisted since it times out)
  3. Add gzip compression and HTTP2 support
  4. See if it's possible to perform the same function without needing to copy files into wwwroot by instead modifying applicationhost.config via XDT

nextjs-server-azuresiteextension's People

Contributors

robdmoore avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.