move server hosting to dns
This commit is contained in:
@@ -260,7 +260,8 @@ pub async fn start(cli: crate::Cli) -> std::io::Result<()> {
|
|||||||
.route(Route::get("/signup.lua"), AppHandler { app_state: app_state.clone(), rate_limit_state: None, handler_type: HandlerType::StaticFile })
|
.route(Route::get("/signup.lua"), AppHandler { app_state: app_state.clone(), rate_limit_state: None, handler_type: HandlerType::StaticFile })
|
||||||
.route(Route::get("/dashboard.lua"), AppHandler { app_state: app_state.clone(), rate_limit_state: None, handler_type: HandlerType::StaticFile })
|
.route(Route::get("/dashboard.lua"), AppHandler { app_state: app_state.clone(), rate_limit_state: None, handler_type: HandlerType::StaticFile })
|
||||||
.route(Route::get("/domain.lua"), AppHandler { app_state: app_state.clone(), rate_limit_state: None, handler_type: HandlerType::StaticFile })
|
.route(Route::get("/domain.lua"), AppHandler { app_state: app_state.clone(), rate_limit_state: None, handler_type: HandlerType::StaticFile })
|
||||||
.route(Route::get("/clanker.txt"), AppHandler { app_state: app_state.clone(), rate_limit_state: None, handler_type: HandlerType::StaticFile });
|
.route(Route::get("/clanker.txt"), AppHandler { app_state: app_state.clone(), rate_limit_state: None, handler_type: HandlerType::StaticFile })
|
||||||
|
.route(Route::get("/search.lua"), AppHandler { app_state: app_state.clone(), rate_limit_state: None, handler_type: HandlerType::StaticFile });
|
||||||
|
|
||||||
let http_port = 8876;
|
let http_port = 8876;
|
||||||
let ca_bootstrap_server = start_ca_bootstrap_server(app_state.clone(), http_port, config.server.address.clone());
|
let ca_bootstrap_server = start_ca_bootstrap_server(app_state.clone(), http_port, config.server.address.clone());
|
||||||
@@ -337,6 +338,10 @@ async fn get_ca_certificate_content(app_state: &AppState) -> std::result::Result
|
|||||||
async fn serve_static_file(ctx: &ServerContext) -> Result<GurtResponse> {
|
async fn serve_static_file(ctx: &ServerContext) -> Result<GurtResponse> {
|
||||||
let path = ctx.path();
|
let path = ctx.path();
|
||||||
|
|
||||||
|
let host_header = ctx.request.headers().get("host")
|
||||||
|
.and_then(|h| h.to_str().ok())
|
||||||
|
.unwrap_or("");
|
||||||
|
|
||||||
// Strip query parameters from the path for static file serving
|
// Strip query parameters from the path for static file serving
|
||||||
let path_without_query = if let Some(query_pos) = path.find('?') {
|
let path_without_query = if let Some(query_pos) = path.find('?') {
|
||||||
&path[..query_pos]
|
&path[..query_pos]
|
||||||
@@ -345,7 +350,11 @@ async fn serve_static_file(ctx: &ServerContext) -> Result<GurtResponse> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let file_path = if path_without_query == "/" || path_without_query == "" {
|
let file_path = if path_without_query == "/" || path_without_query == "" {
|
||||||
"index.html"
|
if host_header == "search.web" {
|
||||||
|
"search.html"
|
||||||
|
} else {
|
||||||
|
"index.html"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if path_without_query.starts_with('/') {
|
if path_without_query.starts_with('/') {
|
||||||
&path_without_query[1..]
|
&path_without_query[1..]
|
||||||
@@ -362,7 +371,13 @@ async fn serve_static_file(ctx: &ServerContext) -> Result<GurtResponse> {
|
|||||||
|
|
||||||
let current_dir = std::env::current_dir()
|
let current_dir = std::env::current_dir()
|
||||||
.map_err(|_| GurtError::invalid_message("Failed to get current directory"))?;
|
.map_err(|_| GurtError::invalid_message("Failed to get current directory"))?;
|
||||||
let frontend_dir = current_dir.join("frontend");
|
|
||||||
|
let frontend_dir = if host_header == "search.web" {
|
||||||
|
current_dir.join("search-engine").join("frontend")
|
||||||
|
} else {
|
||||||
|
current_dir.join("frontend")
|
||||||
|
};
|
||||||
|
|
||||||
let full_path = frontend_dir.join(file_path);
|
let full_path = frontend_dir.join(file_path);
|
||||||
|
|
||||||
match tokio::fs::read_to_string(&full_path).await {
|
match tokio::fs::read_to_string(&full_path).await {
|
||||||
|
|||||||
@@ -4,32 +4,6 @@ class_name CertificateManager
|
|||||||
static var trusted_ca_certificates: Array[String] = []
|
static var trusted_ca_certificates: Array[String] = []
|
||||||
static var ca_cache: Dictionary = {}
|
static var ca_cache: Dictionary = {}
|
||||||
|
|
||||||
static func fetch_cert_via_http(url: String) -> String:
|
|
||||||
var http_request = HTTPRequest.new()
|
|
||||||
|
|
||||||
var main_scene = Engine.get_main_loop().current_scene
|
|
||||||
if not main_scene:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
main_scene.add_child(http_request)
|
|
||||||
|
|
||||||
var error = http_request.request(url)
|
|
||||||
if error != OK:
|
|
||||||
http_request.queue_free()
|
|
||||||
return ""
|
|
||||||
|
|
||||||
var response = await http_request.request_completed
|
|
||||||
http_request.queue_free()
|
|
||||||
|
|
||||||
var result = response[0]
|
|
||||||
var response_code = response[1]
|
|
||||||
var body = response[3]
|
|
||||||
|
|
||||||
if result != HTTPRequest.RESULT_SUCCESS or response_code != 200:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
return body.get_string_from_utf8()
|
|
||||||
|
|
||||||
static func initialize():
|
static func initialize():
|
||||||
load_builtin_ca()
|
load_builtin_ca()
|
||||||
print("Certificate Manager initialized with ", trusted_ca_certificates.size(), " trusted CAs")
|
print("Certificate Manager initialized with ", trusted_ca_certificates.size(), " trusted CAs")
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ local function performSearch(query)
|
|||||||
|
|
||||||
showLoading()
|
showLoading()
|
||||||
|
|
||||||
local url = '/api/search?q=' .. urlEncode(query) .. '&per_page=20'
|
local url = 'https://135.125.163.131:4880/api/search?q=' .. urlEncode(query) .. '&per_page=20'
|
||||||
local response = fetch(url, {
|
local response = fetch(url, {
|
||||||
method = 'GET'
|
method = 'GET'
|
||||||
})
|
})
|
||||||
@@ -120,7 +120,7 @@ local function performLuckySearch()
|
|||||||
local luckyTerms = {'test', 'demo', 'api', 'web', 'site', 'page', 'home', 'index'}
|
local luckyTerms = {'test', 'demo', 'api', 'web', 'site', 'page', 'home', 'index'}
|
||||||
local randomTerm = luckyTerms[math.random(#luckyTerms)]
|
local randomTerm = luckyTerms[math.random(#luckyTerms)]
|
||||||
|
|
||||||
local url = '/api/search?q=' .. urlEncode(randomTerm) .. '&per_page=50'
|
local url = 'https://135.125.163.131:4880/api/search?q=' .. urlEncode(randomTerm) .. '&per_page=50'
|
||||||
local response = fetch(url, {
|
local response = fetch(url, {
|
||||||
method = 'GET'
|
method = 'GET'
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -69,16 +69,6 @@ impl SearchServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.get("/", {
|
|
||||||
move |_ctx| async {
|
|
||||||
Ok(GurtResponse::ok().with_string_body(include_str!("../frontend/search.html")))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.get("/search.lua", {
|
|
||||||
move |_ctx| async {
|
|
||||||
Ok(GurtResponse::ok().with_string_body(include_str!("../frontend/search.lua")))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.get("/health", |_ctx| async {
|
.get("/health", |_ctx| async {
|
||||||
Ok(GurtResponse::ok().with_json_body(&json!({"status": "healthy"}))?)
|
Ok(GurtResponse::ok().with_json_body(&json!({"status": "healthy"}))?)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user