最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firebase cloud functions not updating when deployed - still serving old version of function - Stack Overflow

programmeradmin0浏览0评论

I'm frustrated and confused. I'm trying to deploy my cloud functions but whenever I do they're not updating properly and despite firebase saying that they were updated successfully, keep serving the old function. Here's my index.js:

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

//Cloud functions for user interaction
const charge = require('./func/charge');
const addProduct = require('./func/addProduct');
const removeProduct = require('./func/removeProduct');
const updateTracking = require('./func/updateTracking');

admin.initializeApp(functions.config().firebase);

exports.charge = functions.https.onRequest(charge);
exports.updateTracking = functions.https.onRequest(addProduct);
exports.addProduct = functions.https.onRequest(removeProduct);
exports.removeProduct = functions.https.onRequest(updateTracking)

And here's my addProduct function with everything stripped away. This still doesn't update.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const request = require('request');
const send = require('../send.js');
const cors = require('cors')({origin: '*'});

function addProduct(req, res) {
    console.log('THIS NEVER PRINTS')
    send(res, 500, {
        error: `FAILURE`
    })
}

const appAddProduct = express();
appAddProduct.use(cors);
appAddProduct.post('/', (req, res) => {

    // Catch any unexpected errors to prevent crashing
    try {
        addProduct(req, res);
    } catch(e) {
        console.log(e);
        send(res, 500, {
            error: `The server received an unexpected error. Please try again and contact the site admin if the error persists.`,
        });
    }
});

module.exports = appAddProduct

This is still serving up a success message & status code 200 from an older function with a logic error in it when this should just be serving up a 500 error every time. Something is clearly wrong with the way I've split this into multiple files as that is where the trouble started but I'm not sure where I've gone wrong. Help would be much appreciated.

I'm frustrated and confused. I'm trying to deploy my cloud functions but whenever I do they're not updating properly and despite firebase saying that they were updated successfully, keep serving the old function. Here's my index.js:

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

//Cloud functions for user interaction
const charge = require('./func/charge');
const addProduct = require('./func/addProduct');
const removeProduct = require('./func/removeProduct');
const updateTracking = require('./func/updateTracking');

admin.initializeApp(functions.config().firebase);

exports.charge = functions.https.onRequest(charge);
exports.updateTracking = functions.https.onRequest(addProduct);
exports.addProduct = functions.https.onRequest(removeProduct);
exports.removeProduct = functions.https.onRequest(updateTracking)

And here's my addProduct function with everything stripped away. This still doesn't update.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const request = require('request');
const send = require('../send.js');
const cors = require('cors')({origin: '*'});

function addProduct(req, res) {
    console.log('THIS NEVER PRINTS')
    send(res, 500, {
        error: `FAILURE`
    })
}

const appAddProduct = express();
appAddProduct.use(cors);
appAddProduct.post('/', (req, res) => {

    // Catch any unexpected errors to prevent crashing
    try {
        addProduct(req, res);
    } catch(e) {
        console.log(e);
        send(res, 500, {
            error: `The server received an unexpected error. Please try again and contact the site admin if the error persists.`,
        });
    }
});

module.exports = appAddProduct

This is still serving up a success message & status code 200 from an older function with a logic error in it when this should just be serving up a 500 error every time. Something is clearly wrong with the way I've split this into multiple files as that is where the trouble started but I'm not sure where I've gone wrong. Help would be much appreciated.

Share Improve this question edited Mar 11, 2020 at 15:10 Doug Stevenson 319k36 gold badges456 silver badges473 bronze badges asked Mar 11, 2020 at 15:05 Stuart JohnsonStuart Johnson 1051 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Your exported function names don't match the names of the imported files:

exports.charge = functions.https.onRequest(charge);
exports.updateTracking = functions.https.onRequest(addProduct);
exports.addProduct = functions.https.onRequest(removeProduct);
exports.removeProduct = functions.https.onRequest(updateTracking)

I see that three of the four functions are not paired with the same-named imports. The only one that matches is charge. I suspect you didn't intend to do this.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论