successfully connecting to prod

This commit is contained in:
metacryst
2026-03-17 07:00:27 -05:00
parent 530ea7da89
commit d1e4814593
7 changed files with 43 additions and 31 deletions

View File

@@ -2,10 +2,6 @@
"appId": "so.forum.app", "appId": "so.forum.app",
"appName": "Forum", "appName": "Forum",
"webDir": "dist", "webDir": "dist",
"server": {
"url": "http://sam.local:5173",
"cleartext": true
},
"ios": { "ios": {
"allowsBackForwardNavigationGestures": true "allowsBackForwardNavigationGestures": true
}, },

View File

@@ -5,6 +5,15 @@
### Build and Run (iOS App) ### Build and Run (iOS App)
https://capacitorjs.com/docs/ios#adding-the-ios-platform 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: To Install:
npm install @capacitor/ios npm install @capacitor/ios
npx cap add ios npx cap add ios
@@ -20,7 +29,10 @@ vite build
npx serve dist npx serve dist
If you need to login again: 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 ### Architecture

View File

@@ -1,5 +1,5 @@
const env = import.meta.env
import { Preferences } from '@capacitor/preferences'; import { Preferences } from '@capacitor/preferences';
import util from "../util.js"
class Login extends Shadow { class Login extends Shadow {
inputStyles(el) { inputStyles(el) {
@@ -8,21 +8,21 @@ class Login extends Shadow {
.color("var(--text)") .color("var(--text)")
.border("1px solid var(--accent)") .border("1px solid var(--accent)")
.fontSize(0.9, rem) .fontSize(0.9, rem)
.backgroundColor("var(--darkaccent)") .backgroundColor("var(--searchbackground)")
.borderRadius(12, px) .borderRadius(12, px)
.outline("none") .outline("none")
.onTouch((start) => { .onTouch((start) => {
if(start) { if(start) {
this.style.backgroundColor = "var(--accent)" this.style.backgroundColor = "var(--accent)"
} else { } else {
this.style.backgroundColor = "var(--darkaccent)" this.style.backgroundColor = "var(--searchbackground)"
} }
}) })
} }
render() { render() {
ZStack(() => { 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") .position("absolute")
.top(5, em) .top(5, em)
.left(2, em) .left(2, em)
@@ -43,7 +43,7 @@ class Login extends Shadow {
.margin(1, em).padding(1, em) .margin(1, em).padding(1, em)
.fontSize(0.9, rem) .fontSize(0.9, rem)
.borderRadius(12, px) .borderRadius(12, px)
.background("var(--darkaccent)") .background("var(--searchbackground)")
.color("var(--text)") .color("var(--text)")
.border("1px solid var(--accent)") .border("1px solid var(--accent)")
}) })
@@ -53,7 +53,7 @@ class Login extends Shadow {
e.preventDefault(); e.preventDefault();
const data = new FormData(e.target); const data = new FormData(e.target);
const res = await fetch(`${env.VITE_API_URL}/login`, { const res = await fetch(`${util.HOST}/login`, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json", "X-Client": "mobile" }, headers: { "Content-Type": "application/json", "X-Client": "mobile" },
body: JSON.stringify({ body: JSON.stringify({

View File

@@ -1,5 +1,5 @@
import { Preferences } from '@capacitor/preferences'; import { Preferences } from '@capacitor/preferences';
const env = import.meta.env import util from "../../../util.js"
class Connection { class Connection {
connectionTries = 0; connectionTries = 0;
@@ -14,8 +14,8 @@ class Connection {
const { value: token } = await Preferences.get({ key: 'auth_token' }); const { value: token } = await Preferences.get({ key: 'auth_token' });
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let url = "" let url = ""
if(env.VITE_API_URL) { if(util.HOST) {
url = "wss://" + env.VITE_API_URL.replace(/^https?:\/\//, '') + "/ws" + `?token=${token}`; url = "wss://" + util.HOST.replace(/^https?:\/\//, '') + "/ws" + `?token=${token}`;
} else { } else {
url = "ws://" + window.location.host + "/ws" url = "ws://" + window.location.host + "/ws"
} }

View File

@@ -1,7 +1,9 @@
import util from "../util.js"
class TopBar extends Shadow { class TopBar extends Shadow {
render() { render() {
HStack(() => { HStack(() => {
img(`/db/images/${global.currentNetwork.logo}`, "2.5em", "2.5em") img(`${util.HOST}/db/images/${global.currentNetwork.logo}`, "2.5em", "2.5em")
.borderRadius("50", pct) .borderRadius("50", pct)
.objectFit("cover") .objectFit("cover")
.padding(0.3, em) .padding(0.3, em)

View File

@@ -4,8 +4,6 @@ import "./Home/Login.js"
import "./Home/ConnectionError.js" import "./Home/ConnectionError.js"
import util from "./util.js" import util from "./util.js"
const env = import.meta.env
let Global = class { let Global = class {
Socket = new Socket() Socket = new Socket()
profile = null profile = null
@@ -34,7 +32,7 @@ let Global = class {
async fetchAppData() { async fetchAppData() {
let personalSpace = this.currentNetwork === this.profile let personalSpace = this.currentNetwork === this.profile
if (personalSpace) { return {} } 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() let json = await appData.json()
return json return json
} }
@@ -119,7 +117,7 @@ let Global = class {
async getProfile() { async getProfile() {
try { try {
const res = await util.authFetch(`${env.VITE_API_URL}/profile`, { const res = await util.authFetch(`${util.HOST}/profile`, {
method: "GET", method: "GET",
credentials: "include", credentials: "include",
headers: { headers: {

View File

@@ -1,6 +1,10 @@
import { Preferences } from '@capacitor/preferences'; import { Preferences } from '@capacitor/preferences';
const env = import.meta.env
export default class util { export default class util {
static HOST = env.VITE_API_URL
static async authFetch(url, options = {}) { static async authFetch(url, options = {}) {
const { value: token } = await Preferences.get({ key: 'auth_token' }); const { value: token } = await Preferences.get({ key: 'auth_token' });