Allow embedded jetty to serve an external resources directory

This commit is contained in:
Claude Brisson
2024-04-13 13:54:46 +02:00
parent 3e6cac3eed
commit 4594c5cd44
5 changed files with 29 additions and 2 deletions

5
docker/README.md Normal file
View File

@@ -0,0 +1,5 @@
To run Pairgoth under docker:
- compile Pairgoth and copy `application/target/pairgoth-engine.jar` to `docker/data/app`
- copy `pairgoth.properties.example` to `docker/data/app/pairgoth.properties` and adapt it to your needs
- launch `./run.sh` from within the `docker` directory

View File

@@ -0,0 +1,2 @@
auth = none

View File

@@ -119,6 +119,8 @@ abstract class BaseWebappManager(val webappName: String, loggerName: String) : S
// fail to correctly implement SSL...
disableSSLCertificateChecks()
logger.info("webapp ${webappName} root filesystem path: ${context.getRealPath("")}")
} catch (ioe: IOException) {
logger.error("webapp initialization error", ioe)
}

View File

@@ -6,6 +6,7 @@ import org.jeudego.pairgoth.ratings.RatingsManager
import org.jeudego.pairgoth.util.Translator
import org.slf4j.LoggerFactory
import java.io.IOException
import java.nio.file.Paths
import java.security.SecureRandom
import java.security.cert.X509Certificate
import java.util.*
@@ -14,6 +15,8 @@ import javax.servlet.*
import javax.servlet.annotation.WebListener
import javax.servlet.http.HttpSessionEvent
import javax.servlet.http.HttpSessionListener
import kotlin.io.path.createSymbolicLinkPointingTo
import kotlin.io.path.exists
@WebListener
class WebappManager : BaseWebappManager("View Webapp", "view") {
@@ -22,6 +25,17 @@ class WebappManager : BaseWebappManager("View Webapp", "view") {
override fun contextInitialized(sce: ServletContextEvent) {
super.contextInitialized(sce)
// create a symlink for external resources access
properties.getProperty("cwd")?.let { cwd ->
val target = Paths.get(cwd).resolve("resources")
if (target.exists()) {
val source = Paths.get(context.getRealPath("/")).resolve("resources")
if (!source.exists()) {
source.createSymbolicLinkPointingTo(target)
}
}
}
// publish some properties to the webapp context; for easy access from the template
context.setAttribute("env", properties.getProperty("env") ?: "dev")
context.setAttribute("version", properties.getProperty("version") ?: "?")

View File

@@ -23,6 +23,7 @@ import java.net.URLDecoder
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.security.KeyFactory
import java.security.KeyStore
import java.security.cert.CertificateFactory
@@ -109,10 +110,11 @@ private fun publishProperties() {
}
}
// we want colorized output on linux
if (System.getProperty("os.name") == "Linux")
{
if (System.getProperty("os.name") == "Linux") {
System.setProperty("org.eclipse.jetty.logging.appender.MESSAGE_ESCAPE", "false");
}
// remember the current working directory
System.setProperty("pairgoth.cwd", Paths.get("").toAbsolutePath().toString())
}
private fun extractWarFiles() {
@@ -219,6 +221,8 @@ private fun createContext(webapp: String, contextPath: String) = WebAppContext()
context.contextPath = contextPath
if (webapp == "api") {
context.allowNullPathInfo = true
} else {
}
}