Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust the condition of not returning index.html #398

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/main/java/io/quarkus/search/app/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.validation.constraints.Max;
Expand All @@ -21,8 +20,6 @@
import io.quarkus.search.app.entity.QuarkusVersionAndLanguageRoutingBinder;
import io.quarkus.search.app.quarkusio.QuarkusIO;

import io.quarkus.runtime.LaunchMode;

import org.hibernate.search.engine.search.common.BooleanOperator;
import org.hibernate.search.engine.search.common.ValueModel;
import org.hibernate.search.engine.search.predicate.dsl.SimpleQueryFlag;
Expand All @@ -31,8 +28,6 @@
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.jboss.resteasy.reactive.RestQuery;

import io.vertx.ext.web.Router;

@ApplicationScoped
@Path("/")
public class SearchService {
Expand All @@ -45,16 +40,6 @@ public class SearchService {
@Inject
SearchMapping searchMapping;

public void init(@Observes Router router) {
if (LaunchMode.current().isDevOrTest()) {
return;
}
// DISABLE the index.html route in production
router.getWithRegex("/(index\\.html)?").order(Integer.MIN_VALUE).handler(rc -> {
rc.response().setStatusCode(404).end();
});
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Search for Guides")
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/quarkus/search/app/ui/SearchUiConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.search.app.ui;

import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "search.ui")
public interface SearchUiConfig {

@WithDefault("true")
boolean enabled();
}
24 changes: 24 additions & 0 deletions src/main/java/io/quarkus/search/app/ui/SearchUiService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.search.app.ui;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;

import io.vertx.ext.web.Router;

@ApplicationScoped
public class SearchUiService {

@Inject
SearchUiConfig searchUiConfig;

public void init(@Observes Router router) {
if (searchUiConfig.enabled()) {
return;
}
// DISABLE the index.html route in production
router.getWithRegex("/(index\\.html)?").order(Integer.MIN_VALUE).handler(rc -> {
rc.response().setStatusCode(404).end();
});
}
}
4 changes: 4 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ quarkusio.localized.cn.web-uri=https://cn.quarkus.io/
quarkusio.localized.cn.git-uri=https://github.com/quarkusio/cn.quarkus.io.git
quarkusio.localized.ja.web-uri=https://ja.quarkus.io/
quarkusio.localized.ja.git-uri=https://github.com/quarkusio/ja.quarkus.io.git
# We do not want to show the search index page in production as it is there only for testing purposes:
%prod.search.ui.enabled=false
yrodiere marked this conversation as resolved.
Show resolved Hide resolved
# and we explicitly override it for the staging profile (see `%staging.quarkus.config.profile.parent`):
%staging.search.ui.enabled=true

########################
# Indexing configuration
Expand Down