1
0
Fork 0
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:
Sayantan Santra 2023-04-03 13:50:23 -05:00
parent a1f73c8a9d
commit 3c699d8b02
3 changed files with 13 additions and 1 deletions

View file

@ -1,4 +1,4 @@
const getSiteUrl = async () => await fetch("/api/site") const getSiteUrl = async () => await fetch("/api/siteurl")
.then(res => res.text()) .then(res => res.text())
.then(text => { .then(text => {
if (text == "unset") { if (text == "unset") {

View file

@ -1,3 +1,5 @@
use std::env;
use actix_files::{Files, NamedFile}; use actix_files::{Files, NamedFile};
use actix_web::{ use actix_web::{
get, get,
@ -18,6 +20,14 @@ async fn getall() -> HttpResponse {
HttpResponse::Ok().body(utils::getall()) 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 // 404 error page
#[get("/err/404")] #[get("/err/404")]
async fn error404() -> impl Responder { async fn error404() -> impl Responder {
@ -42,6 +52,7 @@ async fn main() -> std::io::Result<()> {
.service(link_handler) .service(link_handler)
.service(error404) .service(error404)
.service(getall) .service(getall)
.service(siteurl)
.service(Files::new("/", "./resources/").index_file("index.html")) .service(Files::new("/", "./resources/").index_file("index.html"))
}) })
.bind(("0.0.0.0", 2000))? .bind(("0.0.0.0", 2000))?

View file

@ -8,6 +8,7 @@ services:
environment: environment:
# Change if you want to mount the database somewhere else # Change if you want to mount the database somewhere else
# In this case, you can get rid of the db volume below # 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 # - db_url=/urls.sqlite
# Change it in case you want to set the website name # Change it in case you want to set the website name
# displayed in front of the shorturls, defaults to # displayed in front of the shorturls, defaults to