diff --git a/omod/src/main/java/org/openmrs/module/spa/SpaActivator.java b/omod/src/main/java/org/openmrs/module/spa/SpaActivator.java
index f806403..955c7b4 100644
--- a/omod/src/main/java/org/openmrs/module/spa/SpaActivator.java
+++ b/omod/src/main/java/org/openmrs/module/spa/SpaActivator.java
@@ -13,13 +13,23 @@
import org.openmrs.api.GlobalPropertyListener;
import org.openmrs.api.context.Context;
import org.openmrs.module.BaseModuleActivator;
+import org.springframework.web.context.ServletContextAware;
+
+import javax.servlet.ServletContext;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.openmrs.module.spa.SpaConstants.BUNDLED_FRONTEND_DIRECTORY;
+import static org.openmrs.module.spa.SpaConstants.GP_LOCAL_DIRECTORY;
@Slf4j
-public class SpaActivator extends BaseModuleActivator {
+public class SpaActivator extends BaseModuleActivator implements ServletContextAware {
// here so we can register the listener on load and de-register it when stopped
private GlobalPropertyListener spaDirectoryResolver = null;
+ public static ServletContext servletContext;
+
@Override
public void started() {
log.info("SPA module started");
@@ -27,10 +37,25 @@ public void started() {
Context.getAdministrationService().addGlobalPropertyListener(spaDirectoryResolver);
}
+ @Override
+ public void contextRefreshed() {
+ if (!Paths.get(SpaDirectoryResolver.getSpaDirectory(), "index.html").toFile().exists()) {
+ Path bundledFrontend = Paths.get(servletContext.getRealPath("/"), "WEB-INF", BUNDLED_FRONTEND_DIRECTORY);
+ if (bundledFrontend.resolve("index.html").toFile().exists()) {
+ Context.getAdministrationService().setGlobalProperty(GP_LOCAL_DIRECTORY, bundledFrontend.toAbsolutePath().toString());
+ }
+ }
+ }
+
@Override
public void stopped() {
Context.getAdministrationService().removeGlobalPropertyListener(spaDirectoryResolver);
spaDirectoryResolver = null;
log.info("SPA module stopped");
}
+
+ @Override
+ public void setServletContext(ServletContext servletContext) {
+ SpaActivator.servletContext = servletContext;
+ }
}
\ No newline at end of file
diff --git a/omod/src/main/java/org/openmrs/module/spa/SpaConstants.java b/omod/src/main/java/org/openmrs/module/spa/SpaConstants.java
index 795d130..8ea11e5 100644
--- a/omod/src/main/java/org/openmrs/module/spa/SpaConstants.java
+++ b/omod/src/main/java/org/openmrs/module/spa/SpaConstants.java
@@ -19,6 +19,8 @@ private SpaConstants() {}
public static final String DEFAULT_FRONTEND_DIRECTORY = "frontend";
+ public static final String BUNDLED_FRONTEND_DIRECTORY = "bundledFrontend";
+
public static final String GP_LOCAL_DIRECTORY = "spa.local.directory";
}
diff --git a/omod/src/main/java/org/openmrs/module/spa/SpaDirectoryResolver.java b/omod/src/main/java/org/openmrs/module/spa/SpaDirectoryResolver.java
index 6a3ab3c..24b10cb 100644
--- a/omod/src/main/java/org/openmrs/module/spa/SpaDirectoryResolver.java
+++ b/omod/src/main/java/org/openmrs/module/spa/SpaDirectoryResolver.java
@@ -84,6 +84,8 @@ private static void resolveDirectory(String spaDirectory) {
SpaDirectoryResolver.spaDirectory.set(Paths.get(OpenmrsUtil.getApplicationDataDirectory(), DEFAULT_FRONTEND_DIRECTORY).normalize().toAbsolutePath().toString());
}
SpaDirectoryResolver.spaDirectory.set(spaDirectoryPath.normalize().toString());
+ } else {
+ SpaDirectoryResolver.spaDirectory.set(spaDirectory);
}
}
}
diff --git a/omod/src/main/resources/webModuleApplicationContext.xml b/omod/src/main/resources/webModuleApplicationContext.xml
index 1c474c0..ae3a424 100644
--- a/omod/src/main/resources/webModuleApplicationContext.xml
+++ b/omod/src/main/resources/webModuleApplicationContext.xml
@@ -16,6 +16,7 @@
http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
+