我正在使用firebase函数,很难将其作为index.js
index.js
文件如:
index.js
我希望在index.js
中使用express.js
apitest.js
和 子域路由
index.js
apis - > test.js
index.js
const express = require('express');
const functions = require('firebase-functions');
const app = express();
...
const funcTestApi = require('./apis/apitest');
exports.apitest = functions.https.onRequest(app => {
funcTestApi.router(app);
});
apitest.js
exports.router = function(app) {
app.get('/foo', (req, res) => {
res.status(200).json('hello');
});
app.get('/bar', (req, res) => {
res.status(200).json('world');
});
... // other url route
}
日志:
http http://localhost:5000/project-name/us-central1/apitest/foo
http http://localhost:5000/project-name/us-central1/apitest/bar
...
info: Execution took 60000 ms, finished with status: 'timeout'
它不起作用。
答案 0 :(得分:0)
我找到了解决方案。写回程代码,然后是它的工作
<强> apitest.js 强>
exports.router = function(app) {
app.get('/foo', (req, res) => {
res.status(200).json('hello');
});
app.get('/bar', (req, res) => {
res.status(200).json('world');
});
... // other url route
return app; // <-- here
}