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

Make the control panel path configurable #3

Merged
merged 1 commit into from
Jun 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ public interface ControlPanelModuleConfiguration extends Toggleable {
String DEFAULT_ENABLED = "true";
String DEFAULT_ALLOWED_ENVIRONMENTS = Environment.DEVELOPMENT + "," + Environment.TEST;

String DEFAULT_PATH = "/control-panel";

String PREFIX = "micronaut.control-panel";
String PROPERTY_ENABLED = PREFIX + ".enabled";
String PROPERTY_ALLOWED_ENVIRONMENTS = PREFIX + ".allowed-environments";
String PROPERTY_PATH = PREFIX + ".path";

/**
* Enables/disables the control panel module. Default value: {@value #DEFAULT_ENABLED}.
Expand All @@ -54,4 +57,12 @@ public interface ControlPanelModuleConfiguration extends Toggleable {
@Bindable(defaultValue = DEFAULT_ALLOWED_ENVIRONMENTS)
Set<String> getAllowedEnvironments();

/**
* Configures the path where the control panel can be accessed. Default value: {@value #DEFAULT_PATH}.
*
* @return the path where the control panel module is available.
*/
@Bindable(defaultValue = DEFAULT_PATH)
String getPath();

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.micronaut.controlpanel.ui;

import io.micronaut.controlpanel.core.config.ControlPanelModuleConfiguration;
import io.micronaut.http.annotation.Get;

/**
Expand All @@ -25,8 +26,7 @@
*/
public interface ControlPanelApi {

//TODO make configurable
String PATH = "/control-panel";
String PATH = "${" + ControlPanelModuleConfiguration.PROPERTY_PATH + ":" + ControlPanelModuleConfiguration.DEFAULT_PATH + "}";

/**
* Renders the index view.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.micronaut.controlpanel.ui

import io.micronaut.context.ApplicationContext
import io.micronaut.controlpanel.core.config.ControlPanelModuleConfiguration
import io.micronaut.http.HttpStatus
import io.micronaut.http.client.HttpClient
import io.micronaut.runtime.server.EmbeddedServer
import spock.lang.Specification

class ControlPanelControllerPathSpec extends Specification {

void "control panel is accessible in the default path"() {
given:
def server = ApplicationContext.run(EmbeddedServer)
def ctx = server.applicationContext
def client = ctx.createBean(HttpClient, server.URL).toBlocking()

when:
def status = client.exchange(ControlPanelModuleConfiguration.DEFAULT_PATH).status()

then:
status == HttpStatus.OK
}

void "control panel path is configurable"() {
given:
def path = "/cp"
def server = ApplicationContext.run(EmbeddedServer, [(ControlPanelModuleConfiguration.PROPERTY_PATH): path] as Map)
def ctx = server.applicationContext
def client = ctx.createBean(HttpClient, server.URL).toBlocking()

when:
def status = client.exchange(path).status()

then:
status == HttpStatus.OK
}

}
2 changes: 2 additions & 0 deletions src/main/docs/guide/quickStart.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ MICRONAUT_ENVIRONMENTS=dev ./mvnw mn:run
# For Gradle:
MICRONAUT_ENVIRONMENTS=dev ./gradlew run
----

Once the application is running, you can access the control panel at http://localhost:8080/control-panel.