【发布时间】:2018-09-03 12:55:34
【问题描述】:
假设我有 post.js 和以下内容。
var functions = require('firebase-functions');
const express = require('express');
exports.post = functions.https.onRequest((req, res) => {
//stuff.
});
然后我只想将这个函数包含到主文件中,因为它是这样,以便在运行需要 post.js 的 index.js 时,已经导出了 post function。
在 firebase 函数的情况下会运行 https 函数,但现在它不会运行,除非我在需要的文件中再次明确地执行 exposts.post。
我试过了。
index.js
// here
exports.post = require("./post");
//Another functions ...
exports.user = functions.https.onRequest((req, res) => {
//stuff
});
但正因为如此,exports.post = require("./post");,我得到了http://localhost:5000/project-id/us-central1/post-post,它应该只是...us-central1/post。
另外,是否可以让所需模块从所需文件中引用其变量,这样我就不必在 post.js 中对索引中已经存在的变量执行 require .js,例如来自文件系统的“fs”。
谢谢。
【问题讨论】:
-
好的,谢谢链接,这是正确的。
标签: javascript node.js firebase google-cloud-functions systemjs