Post Request Firebase Cloud Functions Timing Out

I know that each HTTP function must end with end() or send(), so I'm thinking that might be related to my issue. I'm building a Shopify app that I want to host on Firebase. I've gotten it to authenticate and install, but when I try to capture the permanent access token via POST, Firebase times out. This same code works fine with ngrok. Entire route function below.

const dotenv = require('dotenv').config();
const functions = require('firebase-functions');
const express = require('express');

const app = express();
const crypto = require('crypto');
const cookie = require('cookie');
const nonce = require('nonce')();
const querystring = require('querystring');
const request = require('request-promise');

const apiKey = process.env.SHOPIFY_API_KEY;
const apiSecret = process.env.SHOPIFY_API_SECRET;
const scopes = 'read_products,read_customers';
const forwardingAddress = '';

app.get('/app/shopify/callback', (req, res) => {
  const { shop, hmac, code, state } = req.query;
  const stateCookie = cookie.parse(req.headers.cookie).__session;

  if (state !== stateCookie) {
    return res.status(403).send('Request origin cannot be verified');

  if (shop && hmac && code) {
    // DONE: Validate request is from Shopify
    const map = Object.assign({}, req.query);
    delete map['signature'];
    delete map['hmac'];
    const message = querystring.stringify(map);

  const generatedHash = crypto
    .createHmac('sha256', apiSecret)

  if (generatedHash !== hmac) {
    return res.status(400).send('HMAC validation failed');

  // Collect permanent access token
  const accessTokenRequestUrl = 'https://' + shop + '/admin/oauth/access_token';
  const accessTokenPayload = {
    client_id: apiKey,
    client_secret: apiSecret,

  // Everything works up until here, { json: accessTokenPayload })
    .then((accessTokenResponse) => {
        const accessToken = accessTokenResponse.access_token;

        // If below is uncommented, it will not show on browser, Firebase seems to timeout on the above
        //res.status(200).send("Got an access token, let's do something with it");

        // Use access token to make API call to 'shop' endpoint
        const shopRequestUrl = 'https://' + shop + '/admin/shop.json';
        const shopRequestHeaders = {
            'X-Shopify-Access-Token': accessToken,

        request.get(shopRequestUrl, { headers: shopRequestHeaders })
            .then((shopResponse) => {
            .catch((error) => {

        .catch((error) => {
  } else {
res.status(400).send('Required parameters missing');

exports.shopifyValidate = functions.https.onRequest(app);


Solved. Turns out you need a paid plan (Blaze, pay as you go) to access external APIs. I upgraded and that solved the issue.