我正在嘗試使用戶組態檔在 appwrite 應用程式中動態化。我希望所有用戶都可以訪問每個用戶個人資料頁面,所以它是這樣的(
我想要的只是一種允許我在我的 vueJS 組件中使用 appwrite nodeJS SDK 的方法。我需要能夠將用戶 ID 傳遞給它并在 VueJS 組件中取回用戶
更新:
下面的代碼有效,我現在可以將資料從 appwrite NodeJS SDK 檢索到我的瀏覽器,但問題是我希望它是動態的。我需要一種將 UserID 從 vue 傳遞到 NodeJS sdk 并檢索資料的方法。
const express = require("express");
const path = require("path");
const app = express(),
bodyParser = require("body-parser");
port = 3080;
// place holder for the data
const sdk = require("node-appwrite");
// Init SDK
let client = new sdk.Client();
let users = new sdk.Users(client);
client
.setEndpoint("http://localhost/v1") // Your API Endpoint
.setProject("myProjectID") // Your project ID
.setKey(
"MySecretApiKey"
); // Your secret API key
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, "../appwrite-app/build")));
app.get("/v1/users", (req, res) => {
console.log("api/users called!");
let promise = users.get("userId");
promise.then(
function (response) {
res.json(response);
},
function (error) {
console.log(error);
}
);
});
app.listen(port, () => {
console.log(`Server listening on the port::${port}`);
});
uj5u.com熱心網友回復:
看起來您正在嘗試在客戶端(瀏覽器)上使用僅節點模塊。您不能在使用本機節點模塊的客戶端上使用任何模塊 - 在這種情況下fs。
因此,您需要從前端應用程式中向服務器應用程式 (API) 發送請求。在 API 上進行任何檔案系統/資料庫檢索,然后將結果發送回客戶端。
將后端/前端撰寫為單獨的應用程式是很常見的——在單獨的檔案夾中,甚至存盤在單獨的存盤庫中。
您也不應該在客戶端上公開任何密鑰。
術語“客戶”也可能存在一些混淆。大多數情況下,它用于指代在 Web 瀏覽器中運行的應用程式,但您也會獲得 node sdk,它們是它們使用的服務的“客戶端”——例如 node-appwrite 在您的情況下。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/463387.html
標籤:javascript 节点.js Vue.js 后端 应用程序
上一篇:Axios實體在第一次呼叫時沒有從本地存盤中獲取令牌-Reactjs django
下一篇:如何洗掉多陣列中的第一個陣列
