mirror of
https://github.com/SinTan1729/chhoto-url
synced 2025-04-26 11:16:51 -05:00
new: Ability to disable frontend
This commit is contained in:
parent
828019998e
commit
2c8f47c0cb
3 changed files with 14 additions and 8 deletions
2
Makefile
2
Makefile
|
@ -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}" \
|
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 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 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
|
-d chhoto-url
|
||||||
docker logs chhoto-url -f
|
docker logs chhoto-url -f
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@ async fn main() -> Result<()> {
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|s| !s.trim().is_empty());
|
.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 an API key is set, check the security
|
||||||
if let Ok(key) = env::var("api_key") {
|
if let Ok(key) = env::var("api_key") {
|
||||||
if !auth::is_key_secure() {
|
if !auth::is_key_secure() {
|
||||||
|
@ -82,7 +84,7 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
// Actually start the server
|
// Actually start the server
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
App::new()
|
let mut app = App::new()
|
||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
.wrap(middleware::Compress::default())
|
.wrap(middleware::Compress::default())
|
||||||
.wrap(
|
.wrap(
|
||||||
|
@ -108,9 +110,13 @@ async fn main() -> Result<()> {
|
||||||
.service(services::delete_link)
|
.service(services::delete_link)
|
||||||
.service(services::login)
|
.service(services::login)
|
||||||
.service(services::logout)
|
.service(services::logout)
|
||||||
.service(services::expand)
|
.service(services::expand);
|
||||||
.service(Files::new("/", "./resources/").index_file("index.html"))
|
|
||||||
.default_service(actix_web::web::get().to(services::error404))
|
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
|
// Hardcode the port the server listens to. Allows for more intuitive Docker Compose port management
|
||||||
.bind(("0.0.0.0", port))?
|
.bind(("0.0.0.0", port))?
|
||||||
|
|
|
@ -79,9 +79,9 @@ pub async fn add_link(
|
||||||
// Return http://
|
// Return http://
|
||||||
if port == 80 {
|
if port == 80 {
|
||||||
url = env::var("site_url")
|
url = env::var("site_url")
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|s| !s.trim().is_empty())
|
.filter(|s| !s.trim().is_empty())
|
||||||
.unwrap_or(String::from("http://localhost"));
|
.unwrap_or(String::from("http://localhost"));
|
||||||
}
|
}
|
||||||
// If the port is 443, remove the port from the returned URL (better for copying and pasting)
|
// If the port is 443, remove the port from the returned URL (better for copying and pasting)
|
||||||
// Return https://
|
// Return https://
|
||||||
|
|
Loading…
Reference in a new issue