Centos的Firebase和express作为后端不工作



我决定使用firebase作为firestore的身份验证和基本表单信息的后端。

在过去,我在云函数中使用过这个express api来实现这一点,并以此为基础进行了新的设置。但我只想在Vultr Centos服务器上使用它,与我的其他api一起使用,现在只想让一切变得更容易,因为我不想让事情过于复杂(直到以后:P(。

现在,我刚刚将这个repo克隆到我的服务器上,我想用poster测试它,但我在访问它时遇到了问题。

我不知道如何解决这个问题,如果有人能给我指明正确的方向,那会让我的生活变得更轻松

这是当前的索引文件和包json文件。我创建了server.listen,试图让它在当前工作。
const functions = require("firebase-functions");
const app = require("express")();
const FBAuth = require("./util/fbAuth");
const server = require('http').createServer(app);
const cors = require("cors");

//This was recently added to try and make it all work easier!
server.listen(port, ipaddress, () => {
});
app.use(cors());
const { db } = require("./util/admin");
const {
getAllWorkflows,
...
} = require("./handlers/workflow");
const {
signup,
login,
uploadImage,
addUserDetails,
getAuthenticatedUser,
getUserDetails
} = require("./handlers/users");
// Workflow Routes
app.get("/Workflows", getAllWorkflows);
...
// user route
app.post("/user", FBAuth, addUserDetails);
app.post("/user/image", FBAuth, uploadImage);
...
// cloud functions are better than firebase library because of load time.

exports.api = functions.https.onRequest(app);

这是package.json文件。

{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "10"
},
"dependencies": {
"busboy": "^0.3.1",
"cors": "^2.8.5",
"express": "^4.17.1",
"firebase": "^7.21.1",
"firebase-admin": "^8.9.0",
"firebase-functions": "^3.11.0",
"firebase-tools": "^7.11.0"
},
"devDependencies": {
"firebase-functions-test": "^0.1.6",
"node-gyp": "^5.0.7"
},
"private": true
}

对于我正在修复的后端,我使用这种工作方式(如果有帮助的话!(,如果有意义的话,我会用上面的firebase东西代替它。它目前工作,可以访问注册和登录功能,对我来说关键的部分只是使用firebase和firestore。

const config = require('../../config');
const express = require('express');
const app = express();
const server = require('http').createServer(app);

server.listen(config.serverParams.port, config.serverParams.address, () => {
console.log(`Server running at http://${server.address().address}:${server.address().port}`);
});

....
app.use((req,res,next)=>{
//can reaplce * with website we want to allow access
res.header('Access-Control-Allow-Origin', 'https://moodmap.app/stats');
next();
});
....
io.on('connection', socket => {

socket.use((packet, next) => {
.....

});

});

非常感谢对此事的任何指导

Firebase和firestore似乎是避免重新发明轮子的好方法,如果我可以简单地键入npm start,并开始与poster一起测试底层功能:s

API是基于我做过的另一个附带项目,它主要是为那些有兴趣进一步探索它的人准备的。

https://github.com/Hewlbern/LightSpeed/tree/master/sigops

很高兴能使用最简单的方法——不过我不想在客户端有任何库,因为我想让我的前端超级高效。谢谢

Cloud Functions不允许您监听任何端口以接收请求。它使用部署期间自动提供的URL自动处理传入连接。对该URL的所有传入请求都将路由到由functions.https.onRequest()构建的导出函数定义的函数回调。

如果您需要监听特定端口的能力,Cloud Functions不是适合您用例的产品。云功能不能部署在自定义服务器上——它只能在谷歌提供的基础设施上工作。

相关内容

最新更新