Server A Local Static Website From A Tauri App
This is what I'm doing to run an Actix web server from a Tauri app.
[package]
name = "tauri_as_web_server"
version = "0.0.1"
description = "Tauri As A Web Server"
license = "MIT"
edition = "2021"
[build-dependencies]
tauri-build = { version = "1.5", features = [] }
[dependencies]
tauri = { version = "1.5", features = ["shell-open"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
actix-web = "4"
actix-files = "0.6.5"
[features]
# this feature is used for production builds or when ``devPath`` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use actix_files as fs;
use actix_web::get;
use actix_web::App;
use actix_web::HttpResponse;
use actix_web::HttpServer;
use actix_web::Responder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
tauri::Builder::default()
.setup(|_app| {
tauri::async_runtime::spawn(
HttpServer::new(|| {
App::new().service(
fs::Files::new("/", "/Users/alan/workshop/neopoligen/_site")
.index_file("index.html"),
)
})
.bind(("127.0.0.1", 3113))?
.run(),
);
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
Ok(())
}
#[get("/")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
-- end of line --