title: how to redirect all server requests to a function in Firebase Hosting
body: <p>Trying to implement SSR with Firebase so I'm using a function to prerender each page of a React App. It's working well except the home page, so it must be either the match is wrong on the firebase redirect or possibly on the express route itself.</p>
  
  <p><strong>firebase.json</strong></p>
  
  <pre><code>{
    "firestore": {
      "rules": "firestore.rules",
      "indexes": "firestore.indexes.json"
    },
    "functions": {
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run lint"
      ]
    },
    "hosting": {
      "public": "build",
      "rewrites": [
        {
          "source": "**",
          "function": "contentServer"
        }
      ],
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ]
    }
  }
  </code></pre>
  
  <p><strong>contentServer.js</strong></p>
  
  <pre><code>import * as functions from 'firebase-functions';
  import * as fs from 'fs';
  import * as path from 'path';
  
  import React from 'react';
  import Helmet from 'react-helmet';
  import { renderToString } from 'react-dom/server';
  import Server from '../browser/Server.js';
  
  const express = require('express');
  
  const app = express();
  
  // might be this? Also tried /**
  
  app.get(['**'], (request, response) =&gt; {
    const context = {};
    const location = request.url;
    console.log('Processing request for ', location);
  
    let appCode;
    try {
      appCode = renderToString(&lt;Server context={context} location={location} /&gt;);
    } catch (err) {
      appCode = 'with error';
    }
  
    // const appState = {
    //   pageTitle: 'Hello World',
    // };
  
    // const preloadedState = JSON.stringify(appState).replace(/&lt;/g, '\\u003c');
    const fileName = path.join(__dirname, '../index.html');
    const htmlTemplate = fs.readFileSync(fileName, 'utf8');
    const head = Helmet.renderStatic();
  
    const responseString = htmlTemplate
      .replace('&lt;div id="root"&gt;&lt;/div&gt;', `&lt;div id="root"&gt;${appCode}&lt;/div&gt;`)
      .replace('&lt;title&gt;React App&lt;/title&gt;', `${head.title}\n${head.link}`);
    return response.send(responseString);
  });
  
  export default functions.https.onRequest(app);
  </code></pre>
  
  <p><strong>Curl</strong></p>
  
  <p>I run <code>firebase serve --only functions,hosting</code></p>
  
  <p>Then use curl to check the response: </p>
  
  <pre><code>curl http://localhost:5000 - does not render the home page - just the standard react page
  curl http://localhost:5000/ - also does not work - just the standard react page.
  curl http://localhost:5000/contact-us - works well and returns the contact us page, all other pages on the site work and trigger the function.
  </code></pre>