首頁  >  問答  >  主體

Leaflet中的資料儲存在哪裡

我有一個使用普通 Leaflet、HTML、CSS 和 JS 啟動並運行的傳單應用程式。目前,它僅位於一個資料夾中,其中包含一個 index.html 檔案、一個 main.js 檔案和一個包含我所有資料的資料夾。數據是geojson數據。我最終希望當我將其在線時,用戶無法訪問我正在使用的數據。我正在尋找關於我應該如何解決這個問題的大局、大綱。

我正在考慮使用 MongoDB 之類的東西來儲存我的數據,但網路上沒有關於如何使用 Leaflet 精確做到這一點的先例或教程。它似乎還需要對我的程式碼進行大量更改,並嘗試將express和節點(?)添加到我的應用程式中。任何想法或範例連結將不勝感激。

P粉883973481P粉883973481237 天前419

全部回覆(1)我來回復

  • P粉505917590

    P粉5059175902024-02-26 00:38:30

    您對 MongoDB 的思考方向是錯誤的,因為這不會以任何額外的方式保護您的資料。

    不可能提供純 HTML 網頁,而是隱藏資料 - 因為任何人都可以在 HTML 原始碼中尋找存取權限。

    您需要的是支援 OAuth 的第三方供應商,例如:

    #他們會向您頒發 JWT,如下面的華為文件所示,然後在伺服器端您需要驗證令牌並決定是否提供資料。

    即使這樣,授權客戶也可以取得並分發您的資料。

    我知道這些東西,因為身為業餘開發者,我編寫了 2 個網頁遊戲,我正在使用這 4 個服務(還有更多)來驗證使用者。

    這是我的伺服器端 Java 程式碼範例,用於驗證華為 Account Kit:

    private void handleHuaweiAuth(HttpServletRequest httpReq, HttpServletResponse httpResp) throws ServletException, IOException {
        字串錯誤 = httpReq.getParameter("錯誤");
        String errorDescription = httpReq.getParameter("error_description");
        字串碼 = httpReq.getParameter("代碼");
        String state = httpReq.getParameter("state");
    
        // 使用鹽和目前月份名稱的雜湊值作為 CSRF 保護
        String Month = md5("PUT SOME SECRET HERE" Calendar.getInstance().getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH));
    
        如果(錯誤!=空){
            拋出新的ServletException(錯誤“:”錯誤描述);
            
        } else if (code != null && Month.equals(state)) {
            MultiMap postParams = new MultiMap<>();
            postParams.put("代碼", 代碼);
            postParams.put("client_id", HUAWEI_ID);
            postParams.put("client_secret", HUAWEI_SECRET);
            postParams.put("redirect_uri", String.format(HUAWEI_REDIRECT_URI, mLanguage));
            postParams.put("grant_type", "authorization_code");
            
            嘗試 {
                String tokenStr = mHttpClient.POST(HUAWEI_TOKEN_URL)
                    .headers(httpFields ->
                    {
                        httpFields.add(new HttpField(HttpHeader.ACCEPT, APPLICATION_JSON));
                        httpFields.add(new HttpField(HttpHeader.CONTENT_TYPE, APPLICATION_URLENCODED));
                    })
                    .body(new StringRequestContent(UrlEncoded.encode(postParams, StandardCharsets.UTF_8, false)))
                    .send().getContentAsString();
                LOG.info("handleHuaweiAuth tokenStr = {}", tokenStr);
                Map tokenMap = (Map) new JSON().fromJSON(tokenStr);
                //String accessToken = tokenMap.get("access_token");
                //字串refreshToken = tokenMap.get("refresh_token");
    
                // 注意:程式碼僅對 1 次使用有效。
                // 如果使用者重新載入此頁面,則將傳回以下內容:
                // {"sub_error":20156,"error_description":"程式碼使用了兩次","error":1101}
                // 解析 token 將導致下面捕獲 NPE 並重定向到首頁
    
                String idToken = tokenMap.get("id_token");
                Map idMap = parseJwt(idToken);
                String sid = idMap.get("sub");
                String photo = idMap.get("圖片");
                字串給定 = idMap.get("given_name");
                String family = idMap.get("family_name");
    
                printGameApp(httpReq, httpResp, 華為, sid, 給定, 家庭, 照片);
                返回;
            } catch (InterruptedException | TimeoutException | ExecutionException | NullPointerException ex) {
                LOG.warn("handleHuaweiAuth", ex);
                // 重定向到首頁
                httpResp.sendRedirect("/");
                返回;
            }
        }
    }

    回覆
    0
  • 取消回覆