mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-07-30 17:15:21 +00:00
Working build
This commit is contained in:
parent
bc3a85daea
commit
7055f135bb
@ -4,7 +4,6 @@ use tauri::{RunEvent, WindowEvent};
|
|||||||
|
|
||||||
// Store backend process handle and logs globally
|
// Store backend process handle and logs globally
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
static BACKEND_PROCESS: Mutex<Option<tauri_plugin_shell::process::CommandChild>> = Mutex::new(None);
|
static BACKEND_PROCESS: Mutex<Option<tauri_plugin_shell::process::CommandChild>> = Mutex::new(None);
|
||||||
@ -538,13 +537,13 @@ pub fn run() {
|
|||||||
.expect("error while building tauri application")
|
.expect("error while building tauri application")
|
||||||
.run(|app_handle, event| {
|
.run(|app_handle, event| {
|
||||||
match event {
|
match event {
|
||||||
RunEvent::ExitRequested { api, .. } => {
|
RunEvent::ExitRequested { .. } => {
|
||||||
add_log("🔄 App exit requested, cleaning up...".to_string());
|
add_log("🔄 App exit requested, cleaning up...".to_string());
|
||||||
cleanup_backend();
|
cleanup_backend();
|
||||||
// Use Tauri's built-in cleanup
|
// Use Tauri's built-in cleanup
|
||||||
app_handle.cleanup_before_exit();
|
app_handle.cleanup_before_exit();
|
||||||
}
|
}
|
||||||
RunEvent::WindowEvent { event: WindowEvent::CloseRequested { api, .. }, .. } => {
|
RunEvent::WindowEvent { event: WindowEvent::CloseRequested {.. }, .. } => {
|
||||||
add_log("🔄 Window close requested, cleaning up...".to_string());
|
add_log("🔄 Window close requested, cleaning up...".to_string());
|
||||||
cleanup_backend();
|
cleanup_backend();
|
||||||
// Allow the window to close
|
// Allow the window to close
|
||||||
|
@ -18,10 +18,8 @@
|
|||||||
"resizable": true,
|
"resizable": true,
|
||||||
"fullscreen": false
|
"fullscreen": false
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"security": {
|
|
||||||
"csp": null
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"bundle": {
|
"bundle": {
|
||||||
"active": true,
|
"active": true,
|
||||||
@ -40,5 +38,6 @@
|
|||||||
"shell": {
|
"shell": {
|
||||||
"open": true
|
"open": true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { invoke } from '@tauri-apps/api/core';
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
import { getApiBaseUrl } from '../utils/api';
|
||||||
|
|
||||||
export class BackendService {
|
export class BackendService {
|
||||||
private static instance: BackendService;
|
private static instance: BackendService;
|
||||||
@ -51,7 +52,7 @@ export class BackendService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getBackendUrl(): string {
|
getBackendUrl(): string {
|
||||||
return 'http://localhost:8080';
|
return getApiBaseUrl() || 'http://localhost:8080';
|
||||||
}
|
}
|
||||||
|
|
||||||
async makeApiCall(endpoint: string, options?: RequestInit): Promise<Response> {
|
async makeApiCall(endpoint: string, options?: RequestInit): Promise<Response> {
|
||||||
|
@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { Stack, Slider, Group, Text, Button, Checkbox, TextInput, Paper } from "@mantine/core";
|
import { Stack, Slider, Group, Text, Button, Checkbox, TextInput, Paper } from "@mantine/core";
|
||||||
import { FileWithUrl } from "../types/file";
|
import { FileWithUrl } from "../types/file";
|
||||||
import { fileStorage } from "../services/fileStorage";
|
import { fileStorage } from "../services/fileStorage";
|
||||||
|
import { makeApiUrl } from "../utils/api";
|
||||||
|
|
||||||
export interface CompressProps {
|
export interface CompressProps {
|
||||||
files?: FileWithUrl[];
|
files?: FileWithUrl[];
|
||||||
@ -85,7 +86,7 @@ const CompressPdfPanel: React.FC<CompressProps> = ({
|
|||||||
formData.append("aggressive", aggressive.toString());
|
formData.append("aggressive", aggressive.toString());
|
||||||
if (expectedSize) formData.append("expectedSize", expectedSize);
|
if (expectedSize) formData.append("expectedSize", expectedSize);
|
||||||
|
|
||||||
const res = await fetch("/api/v1/general/compress-pdf", {
|
const res = await fetch(makeApiUrl("/api/v1/general/compress-pdf"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,7 @@ import { useSearchParams } from "react-router-dom";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { FileWithUrl } from "../types/file";
|
import { FileWithUrl } from "../types/file";
|
||||||
import { fileStorage } from "../services/fileStorage";
|
import { fileStorage } from "../services/fileStorage";
|
||||||
|
import { makeApiUrl } from "../utils/api";
|
||||||
|
|
||||||
export interface MergePdfPanelProps {
|
export interface MergePdfPanelProps {
|
||||||
files: FileWithUrl[];
|
files: FileWithUrl[];
|
||||||
@ -61,7 +62,7 @@ const MergePdfPanel: React.FC<MergePdfPanelProps> = ({
|
|||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/v1/general/merge-pdfs", {
|
const response = await fetch(makeApiUrl("/api/v1/general/merge-pdfs"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { makeApiUrl } from "../utils/api";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Select,
|
Select,
|
||||||
@ -122,7 +123,7 @@ const SplitPdfPanel: React.FC<SplitPdfPanelProps> = ({
|
|||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(endpoint, formData, { responseType: "blob" });
|
const response = await axios.post(makeApiUrl(endpoint), formData, { responseType: "blob" });
|
||||||
const blob = new Blob([response.data], { type: "application/zip" });
|
const blob = new Blob([response.data], { type: "application/zip" });
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
setDownloadUrl(url);
|
setDownloadUrl(url);
|
||||||
|
26
frontend/src/utils/api.ts
Normal file
26
frontend/src/utils/api.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
export const getApiBaseUrl = (): string => {
|
||||||
|
const envUrl = import.meta.env.VITE_API_BASE_URL;
|
||||||
|
|
||||||
|
// In development, use empty string to leverage Vite proxy
|
||||||
|
// In production/Tauri, use localhost:8080 directly
|
||||||
|
// if (envUrl !== undefined) {
|
||||||
|
// console.log(`Using API base URL from environment: ${envUrl}`);
|
||||||
|
// return envUrl;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Fallback for development
|
||||||
|
console.log('Using default API base URL: http://localhost:8080');
|
||||||
|
return 'http://localhost:8080';
|
||||||
|
};
|
||||||
|
|
||||||
|
export const makeApiUrl = (endpoint: string): string => {
|
||||||
|
const baseUrl = getApiBaseUrl();
|
||||||
|
|
||||||
|
// If baseUrl is empty (development), return endpoint as-is for proxy
|
||||||
|
if (!baseUrl) {
|
||||||
|
return endpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For production, combine base URL with endpoint
|
||||||
|
return `${baseUrl}${endpoint}`;
|
||||||
|
};
|
@ -2,8 +2,31 @@ import { defineConfig } from 'vite';
|
|||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
// prevent vite from obscuring rust errors
|
||||||
|
// clearScreen: false,
|
||||||
|
// // Env variables starting with the item of `envPrefix` will be exposed in tauri's source code through `import.meta.env`.
|
||||||
|
// envPrefix: ['VITE_', 'TAURI_ENV_*'],
|
||||||
|
// build: {
|
||||||
|
// // Tauri uses Chromium on Windows and WebKit on macOS and Linux
|
||||||
|
// target:
|
||||||
|
// process.env.TAURI_ENV_PLATFORM == 'windows'
|
||||||
|
// ? 'chrome105'
|
||||||
|
// : 'safari13',
|
||||||
|
// // don't minify for debug builds
|
||||||
|
// minify: !process.env.TAURI_ENV_DEBUG ? 'esbuild' : false,
|
||||||
|
// // produce sourcemaps for debug builds
|
||||||
|
// sourcemap: !!process.env.TAURI_ENV_DEBUG,
|
||||||
|
// },
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
server: {
|
server: {
|
||||||
|
// make sure this port matches the devUrl port in tauri.conf.json file
|
||||||
|
port: 5173,
|
||||||
|
// Tauri expects a fixed port, fail if that port is not available
|
||||||
|
strictPort: true,
|
||||||
|
watch: {
|
||||||
|
// tell vite to ignore watching `src-tauri`
|
||||||
|
ignored: ['**/src-tauri/**'],
|
||||||
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://localhost:8080',
|
target: 'http://localhost:8080',
|
||||||
@ -12,4 +35,4 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
@ -1,6 +1,7 @@
|
|||||||
package stirling.software.SPDF.config;
|
package stirling.software.SPDF.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
@ -26,4 +27,18 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|||||||
"file:" + InstallationPathConfig.getStaticPath(), "classpath:/static/");
|
"file:" + InstallationPathConfig.getStaticPath(), "classpath:/static/");
|
||||||
// .setCachePeriod(0); // Optional: disable caching
|
// .setCachePeriod(0); // Optional: disable caching
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
registry.addMapping("/**")
|
||||||
|
.allowedOrigins(
|
||||||
|
"http://localhost:3000",
|
||||||
|
"http://localhost:5173",
|
||||||
|
"http://tauri.localhost",
|
||||||
|
"tauri://localhost",
|
||||||
|
"app://localhost",
|
||||||
|
"file://")
|
||||||
|
.allowedMethods("*")
|
||||||
|
.allowedHeaders("*");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user