How to setup a rewrite rule on Azure CDN to serve

2019-07-08 04:10发布

问题:

I want to use Azure CDN (which is powered by EdgeCast, apparently) to serve static content for my React + GraphQL web app.

The CDN will pull the static files from a Storage account, and Node.js will handle the GraphQL endpoint.

For the client-side routing to work properly, I need to serve /static/index.html for all requests that don't match the static content path (/static/somefile.ext).

I want to avoid using Node.js to serve the index.html in this fashion:

var express = require('express');
var app = express();

app.all('*', function(req, res){
  res.sendfile("index.html");
});

回答1:

If you are using a Verizon Premium SKU, you can access the rules engine by clicking 'Manage' from the azure portal.

I would use a rule like this to rewrite everything except your static link to index.html



回答2:

You could try to use the "Modify Client Response Header" feature: