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:
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}" \
|
||||
-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
|
||||
|
||||
|
|
|
@ -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))?
|
||||
|
|
|
@ -79,9 +79,9 @@ pub async fn add_link(
|
|||
// Return http://
|
||||
if port == 80 {
|
||||
url = env::var("site_url")
|
||||
.ok()
|
||||
.filter(|s| !s.trim().is_empty())
|
||||
.unwrap_or(String::from("http://localhost"));
|
||||
.ok()
|
||||
.filter(|s| !s.trim().is_empty())
|
||||
.unwrap_or(String::from("http://localhost"));
|
||||
}
|
||||
// If the port is 443, remove the port from the returned URL (better for copying and pasting)
|
||||
// Return https://
|
||||
|
|
Loading…
Reference in a new issue