angular – Websocket在localhost上工作但不是Heroku

前端之家收集整理的这篇文章主要介绍了angular – Websocket在localhost上工作但不是Heroku前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个使用websockets的应用程序(STOMP over SockJs),后端有 Spring.应用程序在Tomcat上的localhost上工作正常(websockets)但是当我部署到Heroku或AWS Web Sockets停止工作时.
我在Angular2中的websocket配置
let sockjs = new SockJS('/rest/add?jwt=' + this.authService.getToken(),{"devel":true,"debug":true},{"transports":["websocket"]});

我也尝试过

{"disabled_transports":["websocket"]}

但两者都失败了.
web.xml中

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
     http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     version="3.1">

<context-param>
    <param-name>spring.profiles.default</param-name>
    <param-value>default</param-value>
</context-param>

<servlet>
    <servlet-name>ws</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:/spring/ws-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
</servlet>
<servlet-mapping>
    <servlet-name>ws</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <async-supported>true</async-supported>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/rest/*</url-pattern>

</filter-mapping>
</web-app>

春天的websocket

<websocket:message-broker
    application-destination-prefix="/app">
    <websocket:stomp-endpoint path="/add">
        <websocket:sockjs/>
    </websocket:stomp-endpoint>
    <websocket:simple-broker prefix="/topic,/queue" />
</websocket:message-broker>

我在Heroku上的应用程序的URL,因此您可以在Web浏览器的控制台中自行检查.
Link
请看更新的日志,这件事让我担心没有TransportHandler

CJyb2xlcyI6IkNVU1RPTUVSIn0.wFqNOduN-lD1-9GIRnG1X1aLJZTxtz9c6vmO7jmPPiE2017-04-06T16:23:32.439917+00:00 app[web.1]: 2017-04-06 16:2332 WARN  DefaultSockJsService:239 - No TransportHandler for http://myapp-ws.herokuapp.com/rest/add/097/eyocvxic/websocket?jwt=eyJhbGciOiJI
好的,所以最后我让它工作了.原来,heroku上的Tomcat没有标准的库集.
首先,我在webapp-runner https://devcenter.heroku.com/articles/java-webapp-runner上本地部署,之后我看到一个奇怪的错误.我测试了几个库,最后添加
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-websocket</artifactId>
    <version>8.5.11</version>
</dependency>

<build>
...
<plugins>
    ...
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.3</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals><goal>copy</goal></goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>com.github.jsimone</groupId>
                            <artifactId>webapp-runner</artifactId>
                            <version>8.5.11.3</version>
                            <destFileName>webapp-runner.jar</destFileName>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

我让它在当地工作.
然后我添加了以下内容的PROCFILE

web:    java $JAVA_OPTS -jar myapp-ws/target/dependency/webapp-runner.jar --port $PORT myapp-ws/target/*.war

并致力于GITHUB(我有与Heroku集成的git),从Heroku内部触发构建并且它有效.

原文链接:https://www.f2er.com/angularjs/140384.html

猜你在找的Angularjs相关文章