【发布时间】:2020-09-28 01:26:51
【问题描述】:
我决定使用 firebase 作为 Firestore 的身份验证和基本表单信息的后端。
过去,我在云函数中使用过这个 express api 来执行此操作,并以此为基础建立了这个新设置。但我希望只在 Vultr Centos 服务器上使用它,将其与我的 api 的其余部分一起使用,并且现在让一切变得更容易,因为我不想让事情变得过于复杂(直到以后:P)。
现在 - 我刚刚将此 repo 克隆到我的服务器上,我想用 postman 对其进行测试,但我无法访问它。
我不知道如何解决这个问题,是否有人能指出正确的方向,这将使我的生活变得更加轻松!
这是当前的索引文件和包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,并开始使用邮递员测试底层功能:s
API 是基于我做的另一个项目,主要是为那些有兴趣探索它的人准备的。
https://github.com/Hewlbern/LightSpeed/tree/master/sigops
很高兴只使用最简单的方法 - 不过我不想在客户端拥有任何库,因为我想让我的前端超级高效。谢谢!
【问题讨论】:
标签: javascript node.js firebase express firebase-authentication