1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2025-04-26 03:06:52 -05:00

new: Ability to disable frontend

This commit is contained in:
Sayantan Santra 2025-04-10 12:45:49 -05:00
parent 828019998e
commit 2c8f47c0cb
Signed by: SinTan1729
GPG key ID: 0538DD402EA50898
3 changed files with 14 additions and 8 deletions

View file

@ -24,7 +24,7 @@ docker-test: docker-local docker-stop
docker run -p ${PORT}:${PORT} --name chhoto-url -e password="${PASSWORD}" -e public_mode="${PUBLIC_MODE}" \
-e site_url="${SITE_URL}" -e db_url="${DB_URL}" -e redirect_method="${REDIRECT_METHOD}" -e port="${PORT}"\
-e slug_style="${SLUG_STYLE}" -e slug_length="${SLUG_LENGTH}" -e cache_control_header="${CACHE_CONTROL_HEADER}"\
-e api_key="${API_KEY}"\
-e api_key="${API_KEY}" -e disable_frontend="${DISABLE_FRONTEND}"\
-d chhoto-url
docker logs chhoto-url -f

View file

@ -40,6 +40,8 @@ async fn main() -> Result<()> {
.ok()
.filter(|s| !s.trim().is_empty());
let disable_frontend = env::var("disable_frontend").is_ok_and(|s| s.trim() == "True");
// If an API key is set, check the security
if let Ok(key) = env::var("api_key") {
if !auth::is_key_secure() {
@ -82,7 +84,7 @@ async fn main() -> Result<()> {
// Actually start the server
HttpServer::new(move || {
App::new()
let mut app = App::new()
.wrap(middleware::Logger::default())
.wrap(middleware::Compress::default())
.wrap(
@ -108,9 +110,13 @@ async fn main() -> Result<()> {
.service(services::delete_link)
.service(services::login)
.service(services::logout)
.service(services::expand)
.service(Files::new("/", "./resources/").index_file("index.html"))
.default_service(actix_web::web::get().to(services::error404))
.service(services::expand);
if !disable_frontend {
app = app.service(Files::new("/", "./resources/").index_file("index.html"));
}
app.default_service(actix_web::web::get().to(services::error404))
})
// Hardcode the port the server listens to. Allows for more intuitive Docker Compose port management
.bind(("0.0.0.0", port))?