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-projectadd the 2 files:server.jsthis file is needed because the Windows Web App needs a js file as an entry point.web.configthis file is use by iisnode which is the bridge between Windows IIS and Node js.
- Edit the
package.jsonfile replace the start scriptstrapi startbynode 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.jsfile. 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 Settingsadd the variables (or import the.envfile):NODE_ENV=PRODUCTIONfor starting Strapi with theProductionconfigurationWEBSITE_NODE_DEFAULT_VERSION=10.14.1WEBSITE_RUN_FROM_PACKAGE=0
- Update the settings in
./config/environments/production/server.jsonaccordingly. 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.jsonaccording to your database. You can also use environment variables and set them throughApplication Settingsentries on the Web App, e.g.DATABASE_HOST,DATABASE_USERNAME, etc. - In
./config/environments/production/response.json, disablegzip; Azure Web App will alreadygzipthe 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 MethodtoZip 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