Skip to content

Explorer Configuration

Esa Puttonen edited this page Oct 6, 2021 · 6 revisions

Deployment guidelines

nFlow Explorer is a single page web application, so it can be deployed to any web server.

Typically nFlow Explorer is embedded as a library (through Maven dependency) in the application that uses nFlow backend components (engine and REST API). See examples for unpacking the library inside the application using Maven or Gradle.

Regardless of where the library is deployed, you need override some properties in config.js. At minimum, you need to configure the endpoint for your nFlow REST API.

In Spring Boot -application you can just copy & paste the default config.js to src/main/resources/static/explorer/config.js file under your application, and make your custom configuration there. This file will override the default config.js that is unpacked from the library dependency.

Configuration options (config.js)

TODO

Environment specific configuration

If your nFlow Explorer configuration contains environment (e.g. development, test, production) specific values, you need a different config.js file for each environment. The method for achieving this depends on your environment.

If you're embedding nFlow as a library in your application as described earlier, you can threat config.js as a template that is read and modified by a Java Servlet with environment specific properties. The code examples below enable configuring environment specific Azure AD client IDs, but the same approach works for any other properties as well.

@Bean
public ServletRegistrationBean<NflowExplorerConfigServlet> nflowExplorerConfig() {
  return new ServletRegistrationBean<NflowExplorerConfigServlet>(new NflowExplorerConfigServlet(env), "/explorer/config.js");
}

public static class NflowExplorerConfigServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
  private final boolean securityDisabled;
  private final String aadClientId;

  public NflowExplorerConfigServlet(Environment env) {
    securityDisabled = env.getProperty("security.disable", Boolean.class, false);
    aadClientId = env.getRequiredProperty("azure.activedirectory.client-id");
  }

  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ClassPathResource cpr = new ClassPathResource("static/explorer/config.js");
    String config = IOUtils.toString(cpr.getInputStream(), StandardCharsets.UTF_8.name());
    if (securityDisabled) {
      config = config.replace("REQUIRE-AAD-LOGIN", "false");
    } else {
      config = config
        .replace("REQUIRE-AAD-LOGIN", "true")
        .replace("AAD-CLIENT-ID", aadClientId);
    }
    IOUtils.write(config, response.getOutputStream(), response.getCharacterEncoding());
  }
}