简体   繁体   中英

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. 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 always handles the HTTP service, and you only write code to handle the incoming requests as you see in the documentation .

If you are trying to serve static content, perhaps you should use Firebase Hosting instead. If you need to integrate a backend for that static content, you can look into integrating Cloud Functions for your API endpoints.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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