vaadin-connect icon indicating copy to clipboard operation
vaadin-connect copied to clipboard

connect client does not work in servlet containers with context

Open manolo opened this issue 6 years ago • 0 comments

When deploying a vaadin-connect app in a servlet container with context, it ask for absolute endpoints. E.g if my app is deployed at http://my-tomcat:8080/starter/ connect client requests are /oauth/token and /services instead of /starter/oauth/token and /starter/services

Workaround is to provide options.tokenEndpoint and options.endpoint but that would make devmode fail, or insert those at build time. Though that is not a good option since deployers might select any word for the context, e.g. /starter.v0.1 etc

You can reproduce by applying this patch to the starter project, and dropping the artifact to the webapps folder in a tomcat installation

diff --git a/pom.xml b/pom.xml
index d28f147..809a6c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>

-    <packaging>jar</packaging>
+    <packaging>war</packaging>
     <groupId>com.vaadin</groupId>
     <artifactId>base-starter-connect</artifactId>
     <version>0.0.1-SNAPSHOT</version>
@@ -128,6 +128,13 @@
             <artifactId>junit-jupiter-api</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-tomcat</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>

     <build>
diff --git a/src/main/java/com/vaadin/connect/starter/StarterApplication.java b/src/main/java/com/vaadin/connect/starter/StarterApplication.java
index fb3db54..0224761 100644
--- a/src/main/java/com/vaadin/connect/starter/StarterApplication.java
+++ b/src/main/java/com/vaadin/connect/starter/StarterApplication.java
@@ -2,6 +2,8 @@ package com.vaadin.connect.starter;

 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

 import com.vaadin.connect.oauth.EnableVaadinConnectOAuthServer;
 import com.vaadin.frontend.server.EnableVaadinFrontendServer;
@@ -12,7 +14,12 @@ import com.vaadin.frontend.server.EnableVaadinFrontendServer;
 @SpringBootApplication
 @EnableVaadinConnectOAuthServer
 @EnableVaadinFrontendServer
-public class StarterApplication {
+public class StarterApplication extends SpringBootServletInitializer {
+
+    @Override
+    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+        return application.sources(StarterApplication.class);
+    }

     /**
      * Main method to run the application.

manolo avatar Jan 25 '19 15:01 manolo