mirror of
https://github.com/minoplhy/chhoto-url.git
synced 2024-12-22 19:57:57 +00:00
Support for providing site_url
This commit is contained in:
parent
a1f73c8a9d
commit
3c699d8b02
@ -1,4 +1,4 @@
|
||||
const getSiteUrl = async () => await fetch("/api/site")
|
||||
const getSiteUrl = async () => await fetch("/api/siteurl")
|
||||
.then(res => res.text())
|
||||
.then(text => {
|
||||
if (text == "unset") {
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::env;
|
||||
|
||||
use actix_files::{Files, NamedFile};
|
||||
use actix_web::{
|
||||
get,
|
||||
@ -18,6 +20,14 @@ async fn getall() -> HttpResponse {
|
||||
HttpResponse::Ok().body(utils::getall())
|
||||
}
|
||||
|
||||
// Get the site URL
|
||||
#[get("/api/siteurl")]
|
||||
async fn siteurl() -> HttpResponse {
|
||||
let site_url = env::var("site_url").unwrap_or(String::from("unset"));
|
||||
println!("{site_url}");
|
||||
HttpResponse::Ok().body(site_url)
|
||||
}
|
||||
|
||||
// 404 error page
|
||||
#[get("/err/404")]
|
||||
async fn error404() -> impl Responder {
|
||||
@ -42,6 +52,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.service(link_handler)
|
||||
.service(error404)
|
||||
.service(getall)
|
||||
.service(siteurl)
|
||||
.service(Files::new("/", "./resources/").index_file("index.html"))
|
||||
})
|
||||
.bind(("0.0.0.0", 2000))?
|
||||
|
@ -8,6 +8,7 @@ services:
|
||||
environment:
|
||||
# Change if you want to mount the database somewhere else
|
||||
# In this case, you can get rid of the db volume below
|
||||
# and instead do a mount manually by specifying the location
|
||||
# - db_url=/urls.sqlite
|
||||
# Change it in case you want to set the website name
|
||||
# displayed in front of the shorturls, defaults to
|
||||
|
Loading…
Reference in New Issue
Block a user