title: Adding GraphQL subscriptions to the existing express app using single server
body: <p>GraphQL playground subscription fails with 400 error code.</p>
  
  <pre><code>WebSocket connection to 'ws://localhost:3000/graphql' failed: Error during WebSocket handshake: Unexpected response code: 400
  </code></pre>
  
  <p>I have an existing code based on express. I've integrated Apollo v2 this way:</p>
  
  <pre><code>const { ApolloServer, PubSub, gql } = require('apollo-server-express');
  
      ...
  
  const app = express();
  
  const server = new ApolloServer({
      typeDefs,
       resolvers       
  });
  
  
  server.applyMiddleware({ app });
  
      ...
  
  app.listen(port, () =&gt;
      console.log(chalk.blue(`App listening on port ${port}!`)),
  );
  </code></pre>
  
  <p>and then i start my existing app on port <code>3000</code> and can access the GraphQL playground on <code>http://localhost:3000/graphql</code>. All queries and mutations work as expected</p>
  
  <p>Now I want to add subscriptions. Turns out I need to use an http server:</p>
  
  <pre><code>const httpServer = http.createServer(app);
  server.installSubscriptionHandlers(httpServer);
  </code></pre>
  
  <p>and then listen to it on another port:</p>
  
  <pre><code>httpServer.listen(3005, () =&gt; {
      console.log(`Server ready at http://localhost:3005${server.graphqlPath}`);
       console.log(`Subscriptions ready at ws://localhost:3005${server.subscriptionsPath}`);
      });  
  </code></pre>
  
  <p>So I have two servers running. My own on port <code>3000</code> and the subscriptions server on <code>3005</code>. Is that the right way? Is it the only way?</p>