By Gianluca Angioni

2020-05-22 22:46:32 8 Comments

I've wrote an API with Firebase functions.

When I'm testing locally firebase serve --only functions, giving a URL as: http://localhost:5000/my-project/us-central1/app

and firebase serve --only function,hosting giving the URL: http://localhost:5000 I get the responses that I'm expecting, but when I deploy my code (firebase deploy) some routes stop working. After deploying once again without changing my code, the routes that previously worked are now broken and the broken ones are now working.

Using Postman to send the request to my API. testing example:


when: The error: Cannot GET /api/articles


const functions = require('firebase-functions');

const express = require('express');
const cookieParser = require('cookie-parser');
const cors = require('cors');
const path = require('path');

const api = require('./routes/api');

const app = express();

app.use(express.urlencoded({extended: false}));

app.use('/api', api.router); = functions.https.onRequest(app);


const express = require('express');
const url = require('url');
const articlesRepo = require('../data/articlesRepo');

const router = express.Router();

router.get('/articles', (req, res)=>{
    articlesRepo.getAllArticles((err, articles)=>{
        if (err) res.status(400).json(err.message);

router.get('/articles/find', (req, res)=>{
    const queryObject = url.parse(req.url,true).query;

    articlesRepo.findArticlesByName(queryObject, (err, articles)=>{
        if (err) res.status(400).json(err.message);

module.exports = {


  "hosting": {
    "public": "public",
    "ignore": [
    "rewrites": [
        "source": "**",
        "function": "app"
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"

Edit After checking once again the broken route I got a new anser:

getaddrinfo EAI_AGAIN my-database-host-url:3306

Edit #2

I don't know why the strange behavior by Functions but I've found out that the last error I got was because I'm trying to send traffic to a server that is not google and this is not allowed by google itself unless you don't want to pay for their Spark or other plans.

I suspect that the issues at the beginning where connected to this fact.


Related Questions

Sponsored Content

Sponsored Content