title: Custom domain Firebase cloudfuntions API
body: <p>I have an Express API already in production using Firebase Cloud Functions but I need to add custom domain to it. I followed <a href="https://www.youtube.com/watch?v=c93iGKyvh3o&amp;t=128s" rel="nofollow noreferrer">these instructions</a> to create a custom domain for Cloud Functions using Firebase Hosting and end up with the following <code>firebase.json</code></p>
  <pre><code>{
    &quot;functions&quot;: {
      &quot;predeploy&quot;: [
        &quot;npm --prefix \&quot;$RESOURCE_DIR\&quot; run lint&quot;,
        &quot;npm --prefix \&quot;$RESOURCE_DIR\&quot; run build&quot;
      ],
      &quot;source&quot;: &quot;functions&quot;
    },
    &quot;firestore&quot;: {
      &quot;rules&quot;: &quot;firestore.rules&quot;,
      &quot;indexes&quot;: &quot;firestore.indexes.json&quot;
    },
    &quot;emulators&quot;: {
      &quot;functions&quot;: {
        &quot;port&quot;: 5001
      },
      &quot;firestore&quot;: {
        &quot;port&quot;: 8080
      },
      &quot;ui&quot;: {
        &quot;enabled&quot;: false
      }
    },
    &quot;hosting&quot;: [{
      &quot;site&quot;: &quot;devbp&quot;,
      &quot;target:&quot;:&quot;devbp&quot;,
      &quot;public&quot;: &quot;public&quot;,
      &quot;rewrites&quot;: [
        {
          &quot;source&quot;: &quot;/api/**&quot;,
          &quot;function&quot;: &quot;api&quot;
        }
      ]
    }]
  }
  </code></pre>
  <p><em>index.ts</em></p>
  <pre><code>import { functions } from './utils/exports-converter';
  import App from './web-api/configs/app';
  
  export * from './functions';
  export * from './backup/schedules';
  export * from './firestore-triggers/credits/credits-triggers'
  export * from './schedules/transactions/aggregations-schedules';
  
  
  export const api = functions.runWith({
      memory: '1GB',
      timeoutSeconds: 300
  }).https.onRequest(App.express);
  </code></pre>
  <p><em>exports-converter.ts</em></p>
  <pre><code>import * as express from &quot;express&quot;;
  import * as functions from &quot;firebase-functions&quot;;
  import * as admin from &quot;firebase-admin&quot;;
  
  export { express, functions, admin };
  </code></pre>
  <p><em>app.ts</em></p>
  <pre><code>import * as cors from &quot;cors&quot;;
  import * as bodyParser from &quot;body-parser&quot;;
  import Routes from &quot;./routes&quot;;
  import { express } from &quot;../../utils/exports-converter&quot;;
  
  class App {
    public express: express.Application;
    constructor() {
      this.express = express();
      this.init();
      this.mountRoutes();
    }
    private init() {
      const corsOptions = { origin: true };
      this.express.use(cors(corsOptions));
      this.express.use(bodyParser.raw());
      this.express.use(bodyParser.json());
      this.express.use(bodyParser.urlencoded({ extended: true }));
    }
    private mountRoutes() {
      Routes.mount(this.express);
    }
  }
  </code></pre>
  <p>The problem is that the endpoints inside the api are not reachable, e.g. <code>GET devbp.web.app/api/user?id=123</code> which returns <code>Cannot GET /api/user</code>. This response indicates that Express is handling the requests (if not, the Hosting would throw a 404 page) but not as expected.</p>
  <p>I believe that I'm missing something in my <code>firebase.json</code> because the same api, as said above, is currently in production.</p>
  <p>Any thoughts on it?</p>