Skip to content

Commit

Permalink
Introduce engine host mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Dec 5, 2024
1 parent 6be189b commit fb2c658
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ MEILISEARCH_MASTER_KEY=master
# Ollama (Optional)
OLLAMA_URL=http://YOUR_IP_HERE
OLLAMA_PORT=11434

# Web Path
WEB_PATH=../web/dist
23 changes: 19 additions & 4 deletions engine/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use std::sync::Arc;
use std::{env, sync::Arc};

use async_std::path::PathBuf;
use instance::InstanceApi;
use items::ItemsApi;
use me::MeApi;
use media::MediaApi;
use oauth::{callback::CallbackApi, login::LoginApi};
use poem::{
get, handler, listener::TcpListener, middleware::Cors, web::Html, EndpointExt, Route, Server,
endpoint::{StaticFileEndpoint, StaticFilesEndpoint},
get, handler,
listener::TcpListener,
middleware::Cors,
web::Html,
EndpointExt, Route, Server,
};
use poem_openapi::{OpenApi, OpenApiService, Tags};
use search::{tasks::SearchTaskApi, SearchApi};
Expand All @@ -18,11 +24,11 @@ use crate::state::AppState;
pub mod instance;
pub mod items;
pub mod me;
pub mod media;
pub mod oauth;
pub mod search;
pub mod sessions;
pub mod users;
pub mod media;

#[derive(Tags)]
enum ApiTags {
Expand Down Expand Up @@ -67,13 +73,22 @@ pub async fn serve(state: AppState) -> Result<(), poem::Error> {

let spec = api_service.spec_endpoint();

let static_files = StaticFilesEndpoint::new(
std::fs::canonicalize(PathBuf::from(
env::var("WEB_PATH").unwrap_or("./web".to_string()),
))
.unwrap(),
)
.fallback_to_index()
.index_file("index.html");

let state = Arc::new(state);

let app = Route::new()
.nest("/api", api_service)
.nest("/openapi.json", spec)
.at("/docs", get(get_openapi_docs))
.at("/", get(get_openapi_docs))
.at("/*", static_files)
.with(Cors::new())
.data(state);

Expand Down
15 changes: 15 additions & 0 deletions engine/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>V3X Property Engine</title>
</head>
<body>
<h1>V3X Property Engine</h1>
<p>It appears you've found a page that doesn't exist.</p>
<p>If you're seeing this page it means the engine you are using does not have the frontend files installed.</p>
<p>Or you are running the engine in dev mode and have not copied the <code>.env.example</code> file to <code>.env</code> yet.</p>
<p>Please visit the <a href="https://github.com/v3xlabs/v3x-property">GitHub repository</a> for more information.</p>
</body>
</html>

0 comments on commit fb2c658

Please sign in to comment.