Skip to content

Commit

Permalink
remove vite proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
timonmerk authored and toni-neurosc committed Oct 4, 2024
1 parent 0ee03ed commit dfbdc79
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 25 deletions.
5 changes: 3 additions & 2 deletions gui_dev/src/components/FileBrowser/FileBrowser.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useReducer, useEffect } from "react";
import { getBackendURL } from "@/utils/getBackendURL";
import {
Box,
Paper,
Expand Down Expand Up @@ -111,7 +112,7 @@ export const FileBrowser = ({

const fetchDrives = async () => {
try {
const response = await fetch("/api/drives");
const response = await fetch(getBackendURL("/api/drives"));
if (!response.ok) throw new Error("Failed to fetch drives");
const data = await response.json();
dispatch({ type: "SET_DRIVES", payload: data.drives });
Expand All @@ -126,7 +127,7 @@ export const FileBrowser = ({

const fetchHomeDirectory = async () => {
try {
const response = await fetch("/api/home_directory");
const response = await fetch(getBackendURL("/api/home_directory"));
if (!response.ok) throw new Error("Failed to fetch home directory");
const data = await response.json();
dispatch({ type: "SET_CURRENT_PATH", payload: data.home_directory });
Expand Down
3 changes: 2 additions & 1 deletion gui_dev/src/components/FileBrowser/QuickAccess.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import { getBackendURL } from "@/utils/getBackendURL";
import {
Paper,
Typography,
Expand Down Expand Up @@ -26,7 +27,7 @@ export const QuickAccessSidebar = ({ onItemClick }) => {

const fetchQuickAccessItems = async () => {
try {
const response = await fetch("/api/quick-access");
const response = await fetch(getBackendURL("/api/quick-access"));
if (!response.ok) throw new Error("Failed to fetch quick access items");
const data = await response.json();
setQuickAccessItems(data.items);
Expand Down
3 changes: 2 additions & 1 deletion gui_dev/src/stores/appInfoStore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createStore } from "./createStore";
import { getBackendURL } from "@/utils/getBackendURL";

export const useAppInfoStore = createStore("appInfo", (set) => ({
version: "",
Expand All @@ -11,7 +12,7 @@ export const useAppInfoStore = createStore("appInfo", (set) => ({
launchMode: "",
fetchAppInfo: async () => {
try {
const response = await fetch("/api/app-info");
const response = await fetch(getBackendURL("/api/app-info"));
const data = await response.json();
set(data);
} catch (error) {
Expand Down
5 changes: 3 additions & 2 deletions gui_dev/src/stores/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// the data source, stream paramerters, the output files paths, etc

import { createPersistStore } from "@/stores/createStore";
import { getBackendURL } from "@/utils/getBackendURL";

// Workflow stages enum-like object
export const WorkflowStage = Object.freeze({
Expand Down Expand Up @@ -76,7 +77,7 @@ export const useSessionStore = createPersistStore("session", (set, get) => ({
// Search for LSL streams

fetchLSLStreams: async () => {
const response = await fetch("/api/LSL-streams");
const response = await fetch(getBackendURL("/api/LSL-streams"));

if (!response.ok) {
set({ lslSource: { selectedStream: null, availableStreams: [] } });
Expand Down Expand Up @@ -195,7 +196,7 @@ export const useSessionStore = createPersistStore("session", (set, get) => ({

fetchChannels: async () => {
try {
const response = await fetch("/api/channels");
const response = await fetch(getBackendURL("/api/channels"));
if (!response.ok) {
throw new Error("Network response was not ok");
}
Expand Down
5 changes: 3 additions & 2 deletions gui_dev/src/stores/settingsStore.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getBackendURL } from "@/utils/getBackendURL";
import { createStore } from "./createStore";

const INITIAL_DELAY = 3000; // wait for Flask
Expand All @@ -6,7 +7,7 @@ const MAX_RETRIES = 100;

const uploadSettingsToServer = async (settings) => {
try {
const response = await fetch("/api/settings", {
const response = await fetch(getBackendURL("/api/settings"), {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -41,7 +42,7 @@ export const useSettingsStore = createStore("settings", (set, get) => ({
fetchSettings: async () => {
try {
console.log("Fetching settings...");
const response = await fetch("/api/settings");
const response = await fetch(getBackendURL("/api/settings"));
if (!response.ok) {
throw new Error("Failed to fetch settings");
}
Expand Down
3 changes: 2 additions & 1 deletion gui_dev/src/stores/socketStore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createStore } from "./createStore";
import { getBackendURL } from "@/utils/getBackendURL";

const WEBSOCKET_URL = "ws";
const WEBSOCKET_URL = getBackendURL("/ws");
const RECONNECT_INTERVAL = 500; // ms

export const useSocketStore = createStore("socket", (set, get) => ({
Expand Down
3 changes: 3 additions & 0 deletions gui_dev/src/utils/getBackendURL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const getBackendURL = (route) => {
return "http://localhost:50001" + route;
}
11 changes: 0 additions & 11 deletions gui_dev/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ export default defineConfig(() => {
},
server: {
port: 54321,
proxy: {
"/api": {
target: `http://localhost:${BACKEND_PORT}`,
changeOrigin: true,
},
"/ws": {
target: `ws://localhost:${BACKEND_PORT}`,
ws: true,
changeOrigin: true,
},
},
},
};
});
11 changes: 6 additions & 5 deletions py_neuromodulation/gui/backend/app_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ def __init__(
self.setup_routes()

# Serve static files
self.mount(
"/",
StaticFiles(directory=PYNM_DIR / "gui" / "frontend", html=True),
name="static",
)
if not dev:
self.mount(
"/",
StaticFiles(directory=PYNM_DIR / "gui" / "frontend", html=True),
name="static",
)

self.pynm_state = pynm_state
self.websocket_manager = WebSocketManager()
Expand Down

0 comments on commit dfbdc79

Please sign in to comment.