Runtime properties renginering
This commit is contained in:
@@ -62,6 +62,15 @@
|
||||
<host>${pairgoth.api.host}</host>
|
||||
<port>${pairgoth.api.port}</port>
|
||||
</httpConnector>
|
||||
<systemProperties>
|
||||
<pairgoth.env>${pairgoth.env}</pairgoth.env>
|
||||
<pairgoth.api.external.url>${pairgoth.api.external.url}</pairgoth.api.external.url>
|
||||
<pairgoth.webapp.external.url>${pairgoth.webapp.external.url}</pairgoth.webapp.external.url>
|
||||
<pairgoth.store>${pairgoth.store}</pairgoth.store>
|
||||
<pairgoth.store.file.path>${pairgoth.store}</pairgoth.store.file.path>
|
||||
<pairgoth.logger.level>${pairgoth.logger.level}</pairgoth.logger.level>
|
||||
<pairgoth.logger.format>${pairgoth.logger.format}</pairgoth.logger.format>
|
||||
</systemProperties>
|
||||
<webApp>
|
||||
<contextPath>${pairgoth.api.context}/</contextPath>
|
||||
</webApp>
|
||||
@@ -87,26 +96,6 @@
|
||||
</sources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>echo-property</id>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<phase>validate</phase>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<echo>///////////////////////////// webapp.port=${webapp.port}</echo>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
-->
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencyManagement>
|
||||
|
@@ -21,7 +21,7 @@ abstract class OAuthHelper {
|
||||
protected get() = WebappManager.getMandatoryProperty("oauth." + name + ".secret")
|
||||
protected val redirectURI: String?
|
||||
protected get() = try {
|
||||
val uri: String = WebappManager.Companion.getProperty("webapp.url") + "/oauth.html"
|
||||
val uri: String = WebappManager.getProperty("webapp.external.url") + "/oauth.html"
|
||||
URLEncoder.encode(uri, "UTF-8")
|
||||
} catch (uee: UnsupportedEncodingException) {
|
||||
logger.error("could not encode redirect URI", uee)
|
||||
|
@@ -62,7 +62,7 @@ class ApiServlet : HttpServlet() {
|
||||
|
||||
// validate request
|
||||
|
||||
if ("dev" == WebappManager.getProperty("webapp.env")) {
|
||||
if ("dev" == WebappManager.getProperty("env")) {
|
||||
response.addHeader("Access-Control-Allow-Origin", "*")
|
||||
}
|
||||
validateAccept(request);
|
||||
|
@@ -62,7 +62,7 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
|
||||
properties[(key as String).removePrefix(PAIRGOTH_PROPERTIES_PREFIX)] = value
|
||||
}
|
||||
|
||||
val env = properties.getProperty("webapp.env")
|
||||
val env = properties.getProperty("env")
|
||||
logger.info("Using profile $env", )
|
||||
|
||||
// set system user agent string to empty string
|
||||
@@ -116,10 +116,10 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
|
||||
return properties.getProperty(prop)
|
||||
}
|
||||
fun getMandatoryProperty(prop: String): String {
|
||||
return properties.getProperty(prop) ?: throw Error("missing property: ${prop}")
|
||||
return getProperty(prop) ?: throw Error("missing property: ${prop}")
|
||||
}
|
||||
|
||||
val webappURL by lazy { getProperty("webapp.url") }
|
||||
val webappURL by lazy { getProperty("webapp.external.url") }
|
||||
|
||||
private val services = mutableMapOf<String, Pair<Runnable, Thread>>()
|
||||
|
||||
|
@@ -1,6 +1,19 @@
|
||||
# webapp
|
||||
webapp.env = dev
|
||||
webapp.url = https://localhost:8085
|
||||
# environment
|
||||
env = dev
|
||||
|
||||
# webapp connector
|
||||
webapp.protocol = http
|
||||
webapp.interface = localhost
|
||||
webapp.port = 8080
|
||||
webapp.context = /
|
||||
webapp.external.url = http://localhost:8080
|
||||
|
||||
# api connector
|
||||
api.protocol = http
|
||||
api.interface = localhost
|
||||
api.port = 8085
|
||||
api.context = /api
|
||||
api.external.url = http://localhost:8085/api
|
||||
|
||||
# store
|
||||
store = file
|
||||
|
48
pom.xml
48
pom.xml
@@ -8,53 +8,7 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>default-properties</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<api.env>dev</api.env>
|
||||
<api.url>http://localhost:8085</api.url>
|
||||
<webapp.env>dev</webapp.env>
|
||||
<webapp.url>http://localhost:8080</webapp.url>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>custom-properties</id>
|
||||
<activation>
|
||||
<file>
|
||||
<exists>../pairgoth.properties</exists>
|
||||
</file>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>read-project-properties</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!--<quiet>true</quiet>-->
|
||||
<files>
|
||||
<file>../pairgoth.properties</file>
|
||||
</files>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<!-- CB: Temporary add my repository, while waiting for SSE Java server module author to incorporate my PR or for me to fork it -->
|
||||
<!-- CB: Temporary add my repository, while waiting for SSE Java server module author to incorporate my PR or for me to fork it -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
|
@@ -70,50 +70,31 @@
|
||||
<outputFolder>${project.build.directory}/generated-resources/css</outputFolder>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--
|
||||
<plugin>
|
||||
<groupId>com.gitlab.haynes</groupId>
|
||||
<artifactId>libsass-maven-plugin</artifactId>
|
||||
<version>0.2.29</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<inputPath>${basedir}/src/main/sass/</inputPath>
|
||||
<inputSyntax>scss</inputSyntax>
|
||||
<outputPath>${project.build.directory}/${project.build.finalName}/css</outputPath>
|
||||
<generateSourceMap>true</generateSourceMap>
|
||||
<sourceMapOutputPath>${project.build.directory}/${project.build.finalName}/css</sourceMapOutputPath>
|
||||
</configuration>
|
||||
</plugin>
|
||||
-->
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
<configuration>
|
||||
<scan>1</scan>
|
||||
<scan>0</scan>
|
||||
<httpConnector>
|
||||
<host>${pairgoth.webapp.host}</host>
|
||||
<port>${pairgoth.webapp.port}</port>
|
||||
</httpConnector>
|
||||
<!--
|
||||
<systemProperties>
|
||||
<pairgoth.api.url>${pairgoth.api.url}</pairgoth.api.url>
|
||||
<pairgoth.env>${pairgoth.env}</pairgoth.env>
|
||||
<pairgoth.api.external.url>${pairgoth.api.external.url}</pairgoth.api.external.url>
|
||||
<pairgoth.webapp.external.url>${pairgoth.webapp.external.url}</pairgoth.webapp.external.url>
|
||||
<pairgoth.store>${pairgoth.store}</pairgoth.store>
|
||||
<pairgoth.store.file.path>${pairgoth.store}</pairgoth.store.file.path>
|
||||
<pairgoth.logger.level>${pairgoth.logger.level}</pairgoth.logger.level>
|
||||
<pairgoth.logger.format>${pairgoth.logger.format}</pairgoth.logger.format>
|
||||
</systemProperties>
|
||||
-->
|
||||
<webApp>
|
||||
<contextPath>${pairgoth.webapp.context}/</contextPath>
|
||||
<resourceBases>${project.basedir}/src/main/webapp,${project.build.directory}/generated-resources/</resourceBases>
|
||||
</webApp>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
|
@@ -21,7 +21,7 @@ abstract class OAuthHelper {
|
||||
protected get() = WebappManager.getMandatoryProperty("oauth." + name + ".secret")
|
||||
protected val redirectURI: String?
|
||||
protected get() = try {
|
||||
val uri: String = WebappManager.Companion.getProperty("webapp.url") + "/oauth.html"
|
||||
val uri: String = WebappManager.Companion.getProperty("webapp.external.url") + "/oauth.html"
|
||||
URLEncoder.encode(uri, "UTF-8")
|
||||
} catch (uee: UnsupportedEncodingException) {
|
||||
logger.error("could not encode redirect URI", uee)
|
||||
|
@@ -11,8 +11,8 @@ class ApiTool {
|
||||
companion object {
|
||||
const val JSON = "application/json"
|
||||
val apiRoot =
|
||||
System.getProperty("pairgoth.api.url")?.let { "${it.removeSuffix("/")}/" }
|
||||
?: System.getProperty("pairgoth.webapp.url")?.let { "${it.removeSuffix("/")}/api/" }
|
||||
System.getProperty("pairgoth.api.external.url")?.let { "${it.removeSuffix("/")}/" }
|
||||
?: System.getProperty("pairgoth.webapp.external.url")?.let { "${it.removeSuffix("/")}/api/" }
|
||||
?: throw Error("no configured API url")
|
||||
}
|
||||
private val client = OkHttpClient()
|
||||
|
@@ -63,11 +63,11 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
|
||||
properties[(key as String).removePrefix(PAIRGOTH_PROPERTIES_PREFIX)] = value
|
||||
}
|
||||
|
||||
val env = properties.getProperty("webapp.env")
|
||||
val env = properties.getProperty("env")
|
||||
logger.info("Using profile {}", )
|
||||
|
||||
// let the view be aware of the environment
|
||||
context.setAttribute("webapp.env", env)
|
||||
context.setAttribute("env", env)
|
||||
|
||||
// set system user agent string to empty string
|
||||
System.setProperty("http.agent", "")
|
||||
@@ -114,10 +114,10 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
|
||||
return properties.getProperty(prop)
|
||||
}
|
||||
fun getMandatoryProperty(prop: String): String {
|
||||
return properties.getProperty(prop) ?: throw Error("missing property: ${prop}")
|
||||
return getProperty(prop) ?: throw Error("missing property: ${prop}")
|
||||
}
|
||||
|
||||
val webappURL by lazy { getProperty("webapp.url") }
|
||||
val webappURL by lazy { getProperty("webapp.external.url") }
|
||||
|
||||
private val services = mutableMapOf<String, Pair<Runnable, Thread>>()
|
||||
|
||||
|
@@ -117,7 +117,7 @@ private fun getResourceProperty(key: String) = serverProps.getProperty(key)?.let
|
||||
private fun launchServer() {
|
||||
// create webapps contexts
|
||||
val webAppContexts = mutableListOf<WebAppContext>()
|
||||
val mode = serverProps["mode"] ?: throw Error("missing property: mode")
|
||||
val mode = serverProps["mode"] ?: "standalone"
|
||||
if (mode == "server" || mode == "standalone") webAppContexts.add(createContext("api", "/api"))
|
||||
if (mode == "client" || mode == "standalone") webAppContexts.add(createContext("view", "/"))
|
||||
|
||||
|
Reference in New Issue
Block a user