From d1e4814593339b21f1bc043424abbbaacfdf47d3 Mon Sep 17 00:00:00 2001 From: metacryst Date: Tue, 17 Mar 2026 07:00:27 -0500 Subject: [PATCH] successfully connecting to prod --- capacitor.config.json | 4 ---- readme.md | 14 +++++++++++++- src/Home/Login.js | 12 ++++++------ src/_/code/ws/Connection.js | 6 +++--- src/components/TopBar.js | 28 +++++++++++++++------------- src/index.js | 6 ++---- src/util.js | 4 ++++ 7 files changed, 43 insertions(+), 31 deletions(-) diff --git a/capacitor.config.json b/capacitor.config.json index 38f3a79..532b34f 100644 --- a/capacitor.config.json +++ b/capacitor.config.json @@ -2,10 +2,6 @@ "appId": "so.forum.app", "appName": "Forum", "webDir": "dist", - "server": { - "url": "http://sam.local:5173", - "cleartext": true - }, "ios": { "allowsBackForwardNavigationGestures": true }, diff --git a/readme.md b/readme.md index 9fdabee..4f196d8 100644 --- a/readme.md +++ b/readme.md @@ -5,6 +5,15 @@ ### Build and Run (iOS App) https://capacitorjs.com/docs/ios#adding-the-ios-platform + +Add this option into the top level of capacitor.config.json if you want the ios app to call the dev server: +"server": { + "url": "http://sam.local:5173", + "cleartext": true +}, + +Otherwise, it will call prod. + To Install: npm install @capacitor/ios npx cap add ios @@ -20,7 +29,10 @@ vite build npx serve dist If you need to login again: -run "localStorage.clear() in the browser dev tools console and then refresh the page. +run localStorage.clear() in the browser dev tools console and then refresh the page. + +### Various Commands +npx cap config - this will list the full configuration currently being used ### Architecture diff --git a/src/Home/Login.js b/src/Home/Login.js index 3f1f13f..7d2d412 100644 --- a/src/Home/Login.js +++ b/src/Home/Login.js @@ -1,5 +1,5 @@ -const env = import.meta.env import { Preferences } from '@capacitor/preferences'; +import util from "../util.js" class Login extends Shadow { inputStyles(el) { @@ -8,21 +8,21 @@ class Login extends Shadow { .color("var(--text)") .border("1px solid var(--accent)") .fontSize(0.9, rem) - .backgroundColor("var(--darkaccent)") + .backgroundColor("var(--searchbackground)") .borderRadius(12, px) .outline("none") .onTouch((start) => { if(start) { this.style.backgroundColor = "var(--accent)" } else { - this.style.backgroundColor = "var(--darkaccent)" + this.style.backgroundColor = "var(--searchbackground)" } }) } render() { ZStack(() => { - img(window.matchMedia('(prefers-color-scheme: dark)') ? "/_/icons/columnwhite.svg" : "/_/icons/logo.svg", window.isMobile() ? "5vmax" : "3vmax") + img(window.matchMedia('(prefers-color-scheme: dark)').matches ? "/_/icons/columnwhite.svg" : "/_/icons/logo.svg", window.isMobile() ? "5vmax" : "3vmax") .position("absolute") .top(5, em) .left(2, em) @@ -43,7 +43,7 @@ class Login extends Shadow { .margin(1, em).padding(1, em) .fontSize(0.9, rem) .borderRadius(12, px) - .background("var(--darkaccent)") + .background("var(--searchbackground)") .color("var(--text)") .border("1px solid var(--accent)") }) @@ -53,7 +53,7 @@ class Login extends Shadow { e.preventDefault(); const data = new FormData(e.target); - const res = await fetch(`${env.VITE_API_URL}/login`, { + const res = await fetch(`${util.HOST}/login`, { method: "POST", headers: { "Content-Type": "application/json", "X-Client": "mobile" }, body: JSON.stringify({ diff --git a/src/_/code/ws/Connection.js b/src/_/code/ws/Connection.js index 93fefee..f1ff450 100644 --- a/src/_/code/ws/Connection.js +++ b/src/_/code/ws/Connection.js @@ -1,5 +1,5 @@ import { Preferences } from '@capacitor/preferences'; -const env = import.meta.env +import util from "../../../util.js" class Connection { connectionTries = 0; @@ -14,8 +14,8 @@ class Connection { const { value: token } = await Preferences.get({ key: 'auth_token' }); return new Promise((resolve, reject) => { let url = "" - if(env.VITE_API_URL) { - url = "wss://" + env.VITE_API_URL.replace(/^https?:\/\//, '') + "/ws" + `?token=${token}`; + if(util.HOST) { + url = "wss://" + util.HOST.replace(/^https?:\/\//, '') + "/ws" + `?token=${token}`; } else { url = "ws://" + window.location.host + "/ws" } diff --git a/src/components/TopBar.js b/src/components/TopBar.js index a10c3fb..8021f8b 100644 --- a/src/components/TopBar.js +++ b/src/components/TopBar.js @@ -1,19 +1,21 @@ +import util from "../util.js" + class TopBar extends Shadow { render() { HStack(() => { - img(`/db/images/${global.currentNetwork.logo}`, "2.5em", "2.5em") - .borderRadius("50", pct) - .objectFit("cover") - .padding(0.3, em) - .background("var(--accent)") - .onTouch(function (start) { - if(start) { - this.style.scale = "0.8" - } else if(start === false) { - this.style.scale = "" - $("sidebar-").toggle() - } - }) + img(`${util.HOST}/db/images/${global.currentNetwork.logo}`, "2.5em", "2.5em") + .borderRadius("50", pct) + .objectFit("cover") + .padding(0.3, em) + .background("var(--accent)") + .onTouch(function (start) { + if(start) { + this.style.scale = "0.8" + } else if(start === false) { + this.style.scale = "" + $("sidebar-").toggle() + } + }) p(global.currentApp()) .color("var(--headertext)") diff --git a/src/index.js b/src/index.js index ccc0758..01b1016 100644 --- a/src/index.js +++ b/src/index.js @@ -4,8 +4,6 @@ import "./Home/Login.js" import "./Home/ConnectionError.js" import util from "./util.js" -const env = import.meta.env - let Global = class { Socket = new Socket() profile = null @@ -34,7 +32,7 @@ let Global = class { async fetchAppData() { let personalSpace = this.currentNetwork === this.profile if (personalSpace) { return {} } - let appData = await fetch(`${env.VITE_API_URL}/api/${personalSpace ? "my" : "org"}data/` + this.currentNetwork.id, {method: "GET"}) + let appData = await fetch(`${util.HOST}/api/${personalSpace ? "my" : "org"}data/` + this.currentNetwork.id, {method: "GET"}) let json = await appData.json() return json } @@ -119,7 +117,7 @@ let Global = class { async getProfile() { try { - const res = await util.authFetch(`${env.VITE_API_URL}/profile`, { + const res = await util.authFetch(`${util.HOST}/profile`, { method: "GET", credentials: "include", headers: { diff --git a/src/util.js b/src/util.js index faec59b..fcf36e0 100644 --- a/src/util.js +++ b/src/util.js @@ -1,6 +1,10 @@ import { Preferences } from '@capacitor/preferences'; +const env = import.meta.env export default class util { + + static HOST = env.VITE_API_URL + static async authFetch(url, options = {}) { const { value: token } = await Preferences.get({ key: 'auth_token' });