This repo is a customoziation of the code generated by the Strapi CLI to make it works on Azure Windows WebApp. To reproduce this repo by your own:
npm create-strapi-app my-project --quickstart
- In the folder
my-project
add the 2 files:server.js
this file is needed because the Windows Web App needs a js file as an entry point.web.config
this file is use by iisnode which is the bridge between Windows IIS and Node js.
- Edit the
package.json
file replace the start scriptstrapi start
bynode server.js
This file replace the CLI strapi start
:
'use strict';
const strapi = require('./node_modules/strapi/lib/index')
strapi().start();
This file is almost the default one generated automaticaly by Azure on a Git deploy. You notice that it refers to the server.js
file. The difference with the default one is the security section:
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="build"/>
</hiddenSegments>
</requestFiltering>
</security>
This section allows to access to the build
folder which contains the Admin panel
- Create a Windows Web App in Azure
- In
Application Settings
add the variables (or import the.env
file):NODE_ENV=PRODUCTION
for starting Strapi with theProduction
configurationWEBSITE_NODE_DEFAULT_VERSION=10.14.1
WEBSITE_RUN_FROM_PACKAGE=0
- Update the settings in
./config/environments/production/server.json
accordingly. Set"port": "${process.env.PORT || 1337}"
and change the value of the"host"
property under"proxy"
to match the public url of the Web App (see: Server Configurations for more info) - (Only in the context of this repo) Create a CosmosDB instance with a MongoDB Api
- In the
Preview features
, enableAggregation Pipeline
- In the
- Update the settings in
./config/environments/production/database.json
according to your database. You can also use environment variables and set them throughApplication Settings
entries on the Web App, e.g.DATABASE_HOST
,DATABASE_USERNAME
, etc. - In
./config/environments/production/response.json
, disablegzip
; Azure Web App will alreadygzip
the responses, so we don't need Strapi to do this (otherwise the browser will have issues decoding the content it downloads due to 2xgzip
) - Set local variable
set NODE_ENV=PRODUCTION
- Build the Admin Panel:
yarn build
- Deploy the app with the Zip Deploy (here from VSCode with the Azure App Service Extension) or through an Azure DevOps Release Pipeline using the Azure Web App Deployment task. Make sure to set the
Deployment Method
toZip Deploy
. - Browse to your App. It could take a while for the first start. Could even end up with an error. Reload the page.
Don't run npm i
, use yarn
instead to be sure to get the right version package