【发布时间】:2019-11-06 12:36:57
【问题描述】:
我尝试向 an example 学习如何在 firebase 上使用 express 和车把。
对于express的方式,我们可以直接将“app”实例发送到“functions.https.onRequest”之类的......
const app = express();
...
app.get('/', (req, res) => {
...
});
exports.app = functions.https.onRequest(app);
据我了解,它之所以有效,是因为“express”的行为类似于 http-node,因此它可以响应“http plain”。
与 hapi 相比,这里是 hello-world
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
});
server.route({
method: 'GET',
path:'/hello',
handler: function (request, reply) {
return reply('hello world');
}
});
server.start((err) => {
console.log('Server running at:', server.info.uri);
});
从 hapi 示例中,是否可以在 firebase 云功能上使用 hapi?
我可以在不启动 express 之类的服务器的情况下使用 hapi 吗?
【问题讨论】:
-
你应该使用 hapi 或 express 与火基地。 Fire base Handels 为您路由,因此不需要路由框架。保持你的函数重量轻。如果你想渲染车把模板只需要车把。
标签: javascript node.js express firebase hapijs