perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

Question: How to setup context path for all request #1088

Closed Pasupathi-Rajamanickam closed 5 years ago

Pasupathi-Rajamanickam commented 5 years ago

I'm looking for an option to set context path all request, I know I can append context path for each and every request that I'm mapping, but what do I do for static folders?

Context path is super critical when we run app behind nginx. So please let me know if there is a way to achieve this scenario.

jakaarl commented 5 years ago

Depends on how you deploy. As standalone, you could try defining the context path in META-INF/context.xml, but I'm not certain if it will have any effect. Deploying as a WAR file, the context path will be determined by the file name, or can be configured in the server configuration.

Pasupathi-Rajamanickam commented 5 years ago

@jakaarl I thought sparkjava is java based framework, I built runnable jar out of it and tried to run. That's the way I'm more inclined to. No more war files 😄 I can't go back to old architecture.

tipsy commented 5 years ago

Unfortunately you can't set a context path using the embedded Jetty server.

Pasupathi-Rajamanickam commented 5 years ago

@tipsy as far I know it's easy to setup. Maybe it's not feasible in sparkjava?

ContextHandler context = new ContextHandler();
context.setContextPath( "/hello" );
context.setHandler( new HelloHandler() );
Server server = new Server(serverPort);
server.setHandler(context);
server.start();
server.join();
tipsy commented 5 years ago

It's pretty easy, yes. There is a PR for it, but it's been open for years.