-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add js-plugins pre-built support (#3056)
Co-authored-by: Colin Alworth <[email protected]>
- Loading branch information
1 parent
34857ec
commit 751a963
Showing
2 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
server/jetty/src/main/java/io/deephaven/server/jetty/JsPlugins.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.deephaven.server.jetty; | ||
|
||
import io.deephaven.configuration.Configuration; | ||
import org.eclipse.jetty.security.ConstraintSecurityHandler; | ||
import org.eclipse.jetty.server.Handler; | ||
import org.eclipse.jetty.servlet.DefaultServlet; | ||
import org.eclipse.jetty.servlet.ErrorPageErrorHandler; | ||
import org.eclipse.jetty.util.resource.Resource; | ||
import org.eclipse.jetty.webapp.WebAppContext; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.util.function.Consumer; | ||
|
||
import static org.eclipse.jetty.servlet.ServletContextHandler.NO_SESSIONS; | ||
|
||
class JsPlugins { | ||
|
||
public static void maybeAdd(Consumer<Handler> addHandler) { | ||
// Note: this would probably be better to live in JettyConfig - but until we establish more formal expectations | ||
// for js plugin configuration and workflows, we'll keep this here. | ||
final String resourceBase = | ||
Configuration.getInstance().getStringWithDefault("deephaven.jsPlugins.resourceBase", null); | ||
if (resourceBase == null) { | ||
return; | ||
} | ||
try { | ||
Resource resource = ControlledCacheResource.wrap(Resource.newResource(resourceBase)); | ||
WebAppContext context = | ||
new WebAppContext(null, "/js-plugins/", null, null, null, new ErrorPageErrorHandler(), NO_SESSIONS); | ||
context.setBaseResource(resource); | ||
context.setInitParameter(DefaultServlet.CONTEXT_INIT + "dirAllowed", "false"); | ||
// Suppress warnings about security handlers | ||
context.setSecurityHandler(new ConstraintSecurityHandler()); | ||
addHandler.accept(context); | ||
} catch (IOException e) { | ||
throw new IllegalStateException(String.format("Unable to resolve resourceBase '%s'", resourceBase), e); | ||
} | ||
} | ||
} |