简体   繁体   English

Firebase 部署有关功能的问题

[英]Firebase deploy problem regarding functions

const functions = require("firebase-functions");
    var PORT=5500;
    var express=
    require('express');
    var router=express.Router();
    var app=express();
    var path = require('path');
    app.use(express.static(__dirname + '../../public'));
    app.get('/', (req, res) => res.sendFile(path.resolve(__dirname +'../public/index.html'))); 
    app.get('/about', (req, res) => res.sendFile(path.resolve(__dirname + '../public/about.html'))); 
    app.get('/instructor', (req, res) => res.sendFile(path.resolve(__dirname + '../../public/instructor.html'))); 

app.listen(PORT, function(){
    console.log('app listening at http://localhost:', PORT)
})
exports.app=functions.https.onRequest(app);

This is the code of my function, but when I actually deploy the website by utilizing "firebase deploy", it only shows index.html and 404.html, not showing other HTML pages such as about.html. This is the code of my function, but when I actually deploy the website by utilizing "firebase deploy", it only shows index.html and 404.html, not showing other HTML pages such as about.html. I think problems come from this code.我认为问题来自这段代码。 Can you please give me some help?你能给我一些帮助吗?

With Cloud Functions, you can't use express or any other HTTP server to listen on some port.使用 Cloud Functions,您不能使用 express 或任何其他 HTTP 服务器侦听某个端口。 Cloud Functions always handles the HTTP service, and you only write code to handle the incoming requests as you see in the documentation . Cloud Functions 始终处理 HTTP 服务,您只需编写代码来处理传入请求,如您在文档中看到的那样。

If you are trying to serve static content, perhaps you should use Firebase Hosting instead.如果您尝试提供 static 内容,也许您应该改用Firebase 托管 If you need to integrate a backend for that static content, you can look into integrating Cloud Functions for your API endpoints.如果您需要为该 static 内容集成后端,您可以考虑为您的 API 端点集成 Cloud Functions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM