import React from 'react'
import express from 'express'
import { renderToString } from 'react-dom/server'
import App from '../src/App.js'
import { StaticRouter } from 'react-router-dom'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
import WebSocket from 'ws'

const store = createStore((state = {}) => state)

const server = express()
  .use(express.static('public'))
  .get('*', (req, res) => {
    res.status(200).send(`<!doctype html><html lang="en">
      <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <script type="text/javascript" src="startd.bundle.js"></script>
      </head>
      <body>
        <div id="root">
          ${renderToString(
            <Provider store={store}>
              <StaticRouter location={req.url} context={{}}>
                <App />
              </StaticRouter>
            </Provider>
          )}
        </div>
      </body>
    </html>`)
  })
  .listen(process.env.PORT || 3000)

const ws = new WebSocket.Server({ server })

ws.on('connection', socket => {
  console.log('hi client connected')
  socket.on('disconnect', () => {
    console.log('client disconnect')
  })
})

@@ -15,15 +15,16 @@
 rom 
-'
+%22
 react
-'
+%22;
 %0Aimp
@@ -44,17 +44,18 @@
 rom 
-'
+%22
 express
-'
+%22;
 %0Aimp
@@ -78,25 +78,25 @@
 ring %7D from 
-'
+%22
 react-dom/se
@@ -99,17 +99,18 @@
 m/server
-'
+%22;
 %0Aimport 
@@ -118,17 +118,17 @@
 pp from 
-'
+%22
 ../src/A
@@ -132,17 +132,18 @@
 c/App.js
-'
+%22;
 %0Aimport 
@@ -160,25 +160,25 @@
 uter %7D from 
-'
+%22
 react-router
@@ -181,17 +181,18 @@
 uter-dom
-'
+%22;
 %0Aimport 
@@ -216,15 +216,16 @@
 rom 
-'
+%22
 redux
-'
+%22;
 %0Aimp
@@ -246,17 +246,17 @@
  %7D from 
-'
+%22
 react-re
@@ -258,17 +258,18 @@
 ct-redux
-'
+%22;
 %0Aimport 
@@ -287,12 +287,13 @@
 rom 
-'ws'
+%22ws%22;
 %0A%0Aco
@@ -338,16 +338,17 @@
 %3E state)
+;
 %0A%0Aconst 
@@ -392,16 +392,16 @@
 tic(
-'
+%22
 public
-'
+%22
 ))%0A 
@@ -410,11 +410,11 @@
 get(
-'*'
+%22*%22
 , (r
@@ -654,16 +654,17 @@
 t%22 src=%22
+/
 startd.b
@@ -993,16 +993,17 @@
 /html%3E%60)
+;
 %0A  %7D)%0A  
@@ -1035,16 +1035,17 @@
 %7C%7C 3000)
+;
 %0A%0Aconst 
@@ -1085,16 +1085,17 @@
 r %7D)
+;
 %0A%0Aws.on(
 'con
@@ -1090,17 +1090,17 @@
 %0A%0Aws.on(
-'
+%22
 connecti
@@ -1101,17 +1101,17 @@
 nnection
-'
+%22
 , socket
@@ -1130,17 +1130,17 @@
 ole.log(
-'
+%22
 hi clien
@@ -1150,18 +1150,19 @@
 onnected
-')
+%22);
 %0A  socke
@@ -1166,17 +1166,17 @@
 cket.on(
-'
+%22
 disconne
@@ -1177,17 +1177,17 @@
 sconnect
-'
+%22
 , () =%3E 
@@ -1204,17 +1204,17 @@
 ole.log(
-'
+%22
 client d
@@ -1226,15 +1226,18 @@
 nect
-')
+%22);
 %0A  %7D)
+;
 %0A%7D)
+;
 %0A

fix bundle route