From 530d0625f411168f04531cd6767b5f7cc654131d Mon Sep 17 00:00:00 2001 From: Jim McGaw Date: Tue, 28 Feb 2023 23:00:06 -0500 Subject: [PATCH] attempts to connect to localhost:8080 WIP --- capacitor.config.json | 12 +++++++++++- server.go | 1 + src/store/epics/chatEpics.js | 1 - src/utils/miniLock.js | 1 - src/utils/sessions.js | 34 +++++++++++++++++++++++++--------- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/capacitor.config.json b/capacitor.config.json index c63901b..e7ee0ab 100644 --- a/capacitor.config.json +++ b/capacitor.config.json @@ -3,7 +3,17 @@ "appName": "LeapChat", "webDir": "build", "bundledWebRuntime": false, + "plugins": { + "CapacitorHttp": { + "enabled": true + } + }, "server": { - "hostname": "localhost:8080" + "cleartext": "true", + "allowNavigation": [ + "192.168.1.247:8080/*", + "localhost:8080/*", + "leapchat.org/*" + ] } } diff --git a/server.go b/server.go index e5e1bb5..0650f09 100644 --- a/server.go +++ b/server.go @@ -74,6 +74,7 @@ func ProductionServer(srv *http.Server, httpsAddr, domain string, manager *autoc func Login(m *miniware.Mapper, pgClient *PGClient) func(w http.ResponseWriter, req *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + //w.Header().Set("Access-Control-Allow-Origin", "*") mID, keypair, err := parseMinilockID(req) if err != nil { WriteErrorStatus(w, "Error: invalid miniLock ID", diff --git a/src/store/epics/chatEpics.js b/src/store/epics/chatEpics.js index e79216d..6783337 100644 --- a/src/store/epics/chatEpics.js +++ b/src/store/epics/chatEpics.js @@ -137,7 +137,6 @@ const ownUserStatusEpic = (action$, store) => .map(() => userStatusSent()) ) .catch(error => { - console.error(error); return Observable.of(alertWarning('Error sending user status.')); }); diff --git a/src/utils/miniLock.js b/src/utils/miniLock.js index 174fa15..3e5a86b 100755 --- a/src/utils/miniLock.js +++ b/src/utils/miniLock.js @@ -443,7 +443,6 @@ miniLock.crypto.decryptFile = function ( ); miniLock.file.read(file, 12, headerLength + 12, function (header) { try { - alert(header.data); header = nacl.util.encodeUTF8(header.data); header = JSON.parse(header); } diff --git a/src/utils/sessions.js b/src/utils/sessions.js index 798d240..c65a037 100644 --- a/src/utils/sessions.js +++ b/src/utils/sessions.js @@ -1,19 +1,35 @@ import { getEmail, getPassphrase } from '../utils/encrypter'; import miniLock from '../utils/miniLock'; +import { Capacitor } from '@capacitor/core'; +import { CapacitorHttp } from '@capacitor/core'; // TODO: will be different host from a mobile device, probably if (!window) -const authUrl = `${window.location.origin}/api/login`; +let authUrl = `${window.location.origin}/api/login`; +if (Capacitor.isNativePlatform()){ + authUrl = "http://192.168.1.247:8080/api/login"; +} -async function connectWithAuthRequest(initiateConnection, mID, secretKey, isNewPassphrase) { - alert(authUrl); - const response = await fetch(authUrl, { - method: "GET", - headers: { - 'X-Minilock-Id': mID - } - }); +async function connectWithAuthRequest(initiateConnection, mID, secretKey, isNewPassphrase) { + let response; + if (Capacitor.isNativePlatform()){ + response = await CapacitorHttp.request({ + url: authUrl, + headers: { + 'X-Minilock-Id': mID + }, + method: 'GET' + }); + } else { + response = await fetch(authUrl, { + method: "GET", + headers: { + 'X-Minilock-Id': mID + } + }); + } + const message = await response.blob(); miniLock.crypto.decryptFile(message, mID, secretKey, function (fileBlob, saveName, senderID) {