resolve public url dynamically, remove publicUrl config element

This commit is contained in:
Athou
2024-08-14 21:07:45 +02:00
parent e170dfe60b
commit d612d83874
7 changed files with 21 additions and 32 deletions

View File

@@ -1,6 +1,5 @@
package com.commafeed.frontend.servlet;
import java.net.URI;
import java.time.Instant;
import java.util.Date;
@@ -14,6 +13,7 @@ import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.NewCookie;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
@Path("/logout")
@PermitAll
@@ -21,16 +21,19 @@ import jakarta.ws.rs.core.Response;
public class LogoutServlet {
private final CommaFeedConfiguration config;
private final UriInfo uri;
private final String cookieName;
public LogoutServlet(CommaFeedConfiguration config, @ConfigProperty(name = "quarkus.http.auth.form.cookie-name") String cookieName) {
public LogoutServlet(CommaFeedConfiguration config, UriInfo uri,
@ConfigProperty(name = "quarkus.http.auth.form.cookie-name") String cookieName) {
this.config = config;
this.uri = uri;
this.cookieName = cookieName;
}
@GET
public Response get() {
NewCookie removeCookie = new NewCookie.Builder(cookieName).maxAge(0).expiry(Date.from(Instant.EPOCH)).path("/").build();
return Response.temporaryRedirect(URI.create(config.publicUrl())).cookie(removeCookie).build();
return Response.temporaryRedirect(uri.getBaseUri()).cookie(removeCookie).build();
}
}

View File

@@ -26,6 +26,7 @@ import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import lombok.RequiredArgsConstructor;
@Path("/next")
@@ -40,12 +41,13 @@ public class NextUnreadServlet {
private final FeedEntryService feedEntryService;
private final CommaFeedConfiguration config;
private final AuthenticationContext authenticationContext;
private final UriInfo uri;
@GET
public Response get(@QueryParam("category") String categoryId, @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
User user = authenticationContext.getCurrentUser();
if (user == null) {
return Response.temporaryRedirect(URI.create(config.publicUrl())).build();
return Response.temporaryRedirect(uri.getBaseUri()).build();
}
FeedEntryStatus status = unitOfWork.call(() -> {
@@ -71,7 +73,7 @@ public class NextUnreadServlet {
return s;
});
String url = status == null ? config.publicUrl() : status.getEntry().getUrl();
String url = status == null ? uri.getBaseUri().toString() : status.getEntry().getUrl();
return Response.temporaryRedirect(URI.create(url)).build();
}
}