Mountain/Binary/Build/LocalhostPlugin.rs
1//! # Localhost Plugin Module
2//!
3//! Configures and creates the Tauri localhost plugin with CORS headers for
4//! Service Workers.
5
6use tauri::plugin::TauriPlugin;
7
8/// Creates and configures the localhost plugin with CORS headers preconfigured.
9///
10/// # Arguments
11///
12/// * `ServerPort` - The port number for the localhost server
13///
14/// # Returns
15///
16/// A configured `tauri_plugin_localhost::TauriPlugin` instance.
17///
18/// # CORS Configuration
19///
20/// The plugin is configured with permissive CORS headers to support Service
21/// Worker and frontend integration:
22/// - Access-Control-Allow-Origin: * (allows all origins)
23/// - Access-Control-Allow-Methods: GET, POST, OPTIONS, HEAD
24/// - Access-Control-Allow-Headers: Content-Type, Authorization, Origin, Accept
25pub fn LocalhostPlugin<R:tauri::Runtime>(ServerPort:u16) -> TauriPlugin<R> {
26 tauri_plugin_localhost::Builder::new(ServerPort)
27 .on_request(|_, Response| {
28 // Set CORS headers to allow cross-origin requests from Service Workers
29 Response.add_header("Access-Control-Allow-Origin", "*");
30 Response.add_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS, HEAD");
31 Response.add_header("Access-Control-Allow-Headers", "Content-Type, Authorization, Origin, Accept");
32 })
33 .build()
34}