mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-12-26 07:38:36 -06:00
Support for providing site_url
This commit is contained in:
parent
a1f73c8a9d
commit
3c699d8b02
3 changed files with 13 additions and 1 deletions
|
@ -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 a new issue