fix redirecting user correctly to the correct backend location
This commit is contained in:
parent
8005d7192e
commit
e0186959b1
@ -3,11 +3,6 @@ import PocketBase from "pocketbase";
|
||||
import { serializeNonPOJOs } from "$lib/utils";
|
||||
|
||||
export const handle = sequence(async ({ event, resolve }) => {
|
||||
// Use optional chaining and nullish coalescing for safer property access
|
||||
const regionHeader =
|
||||
event?.request?.headers?.get("x-vercel-id") ??
|
||||
"fra1::fra1::8t4xg-1700258428633-157d82fdfcc7";
|
||||
|
||||
const ip =
|
||||
event.request.headers.get("x-forwarded-for") ||
|
||||
event.request.headers.get("remote-address");
|
||||
@ -38,7 +33,7 @@ export const handle = sequence(async ({ event, resolve }) => {
|
||||
: import.meta.env.VITE_EU_WS_URL;
|
||||
|
||||
event.locals = {
|
||||
region: decodeURIComponent(regionHeader),
|
||||
isUSRegion: isUS,
|
||||
pb: new PocketBase(pbURL),
|
||||
apiURL,
|
||||
fastifyURL,
|
||||
|
||||
@ -5,13 +5,11 @@
|
||||
export let data;
|
||||
export let availableCash;
|
||||
export let holdingShares;
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
|
||||
let fastifyURL;
|
||||
|
||||
userRegion.subscribe(value => {
|
||||
if (usRegion.includes(value)) {
|
||||
if (value) {
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
} else {
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
|
||||
@ -7,14 +7,12 @@
|
||||
let executiveList = [];
|
||||
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
let apiURL;
|
||||
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
||||
|
||||
|
||||
userRegion?.subscribe(value => {
|
||||
if (usRegion?.includes(value)) {
|
||||
if (value) {
|
||||
apiURL = import.meta.env.VITE_USEAST_API_URL;
|
||||
} else {
|
||||
apiURL = import.meta.env.VITE_EU_API_URL;
|
||||
|
||||
@ -37,7 +37,10 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const closePopup = document.getElementById('feedbackInfo');
|
||||
closePopup?.dispatchEvent(new MouseEvent('click'))
|
||||
|
||||
const userId = data?.user?.id ?? '';
|
||||
|
||||
const postData = {'user': userId,
|
||||
@ -65,8 +68,6 @@
|
||||
style: 'border-radius: 200px; background: #333; color: #fff;'});
|
||||
}
|
||||
|
||||
const closePopup = document.getElementById('feedbackInfo');
|
||||
closePopup?.dispatchEvent(new MouseEvent('click'))
|
||||
|
||||
rating = '';
|
||||
|
||||
|
||||
@ -6,14 +6,13 @@ import { fade } from 'svelte/transition';
|
||||
|
||||
let secFilingsList;
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
let apiURL;
|
||||
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
||||
|
||||
|
||||
userRegion?.subscribe(value => {
|
||||
if (usRegion?.includes(value)) {
|
||||
if (value) {
|
||||
apiURL = import.meta.env.VITE_USEAST_API_URL;
|
||||
} else {
|
||||
apiURL = import.meta.env.VITE_EU_API_URL;
|
||||
|
||||
@ -8,13 +8,10 @@
|
||||
export let holdingShares;
|
||||
|
||||
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
let fastifyURL;
|
||||
|
||||
userRegion.subscribe(value => {
|
||||
if (usRegion.includes(value)) {
|
||||
if (value) {
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
} else {
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
|
||||
@ -2,13 +2,12 @@
|
||||
|
||||
import { userRegion, searchBarData, stockTicker, etfTicker, screenWidth} from '$lib/store';
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
let apiURL;
|
||||
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
||||
|
||||
|
||||
userRegion.subscribe(value => {
|
||||
if (usRegion.includes(value)) {
|
||||
if (value) {
|
||||
apiURL = import.meta.env.VITE_USEAST_API_URL;
|
||||
} else {
|
||||
apiURL = import.meta.env.VITE_EU_API_URL;
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import PocketBase from "pocketbase";
|
||||
import { userRegion } from "$lib/store";
|
||||
|
||||
const usRegion = ["cle1", "iad1", "pdx1", "sfo1"];
|
||||
|
||||
let pbUrl;
|
||||
|
||||
userRegion.subscribe((value) => {
|
||||
if (usRegion?.includes(value)) {
|
||||
if (value) {
|
||||
pbUrl = import.meta.env.VITE_USEAST_POCKETBASE_URL;
|
||||
console.log("US region for pocketbase");
|
||||
} else {
|
||||
pbUrl = import.meta.env.VITE_EU_POCKETBASE_URL;
|
||||
console.log("EU region for pocketbase");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
import { userRegion } from "$lib/store";
|
||||
|
||||
const usRegion = ["cle1", "iad1", "pdx1", "sfo1"];
|
||||
|
||||
let fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
|
||||
userRegion.subscribe((value) => {
|
||||
if (usRegion.includes(value)) {
|
||||
if (value) {
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
} else {
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
export const load = ({ locals, cookies }) => {
|
||||
const { user, region, apiURL, fastifyURL, wsURL, apiKey } = locals;
|
||||
const { user, isUSRegion, apiURL, fastifyURL, wsURL, apiKey } = locals;
|
||||
|
||||
return {
|
||||
user: user || undefined,
|
||||
region,
|
||||
isUSRegion,
|
||||
cookieConsent: cookies?.get("cookie-consent"),
|
||||
apiURL,
|
||||
fastifyURL,
|
||||
|
||||
@ -78,7 +78,7 @@ async function detectSWUpdate() {
|
||||
})
|
||||
}
|
||||
|
||||
$userRegion = data?.region?.split("::")[0];
|
||||
$userRegion = data?.isUSRegion
|
||||
|
||||
let hideHeader = false;
|
||||
|
||||
|
||||
@ -13,18 +13,6 @@
|
||||
|
||||
let cloudFrontUrl = import.meta.env.VITE_IMAGE_URL;
|
||||
|
||||
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
let fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL; // Set a default FASTIFY URL
|
||||
userRegion.subscribe(value => {
|
||||
if (usRegion.includes(value)) {
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
} else {
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
}
|
||||
});
|
||||
|
||||
let isLoaded = false;
|
||||
|
||||
|
||||
@ -34,7 +22,7 @@ if (usRegion.includes(value)) {
|
||||
{
|
||||
const postData = {'userId': data?.user?.id};
|
||||
|
||||
const response = await fetch(fastifyURL+'/get-portfolio', {
|
||||
const response = await fetch(data?.fastifyURL+'/get-portfolio', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user