const WebSocket = require('ws')
const app = require('express')()
const server = require('http').createServer(app)
const WebSocketServer = require('ws').Server
const wss = new WebSocketServer({ server: server })
const port = process.env.PORT || 3333

const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});
//rest
app.get('/api/contact', (req, res) => {
    console.log('/api/contact')
    res.json([
        {
            id: '123',
            name: 'Ivan'
        }
    ])
})

app.post('/login', (req, res) => {
    console.log('/login')
    res.end({
        token:'test token'
    })
})
app.post('/logout', (req, res) => {
    console.log('/logout')

    res.json({})
})

//ws
wss.on('connection', function connection(ws) {
    console.log('on connect')
    ws.on('message', function message(data) {
        console.log('on message')
        // Broadcast to everyone else.
        wss.clients.forEach(function each(client) {
            if (client == ws) client.send(data);
        })
    })
})



const serv = server.listen(port, function () {
    console.log('Express server listening on %d, in %s mode', port, app.get('env'));
})



@@ -733,16 +733,66 @@
  %5D)%0A%7D)%0A%0A
+const TOKEN = %7B%0A        token:'test token'%0A    %7D;%0A
 app.post
@@ -846,56 +846,212 @@
 gin'
-)%0A    res.end(%7B%0A        token:'test token'%0A    %7D
+, req.body)%0A    res.json(TOKEN)%0A%7D)%0Aapp.post('/logout', (req, res) =%3E %7B%0A    console.log('/logout')%0A%0A    res.json(%7B%7D)%0A%7D)%0Aapp.post('/validate', (req, res) =%3E %7B%0A    console.log('/validate')%0A    res.json(TOKEN
 )%0A%7D)
@@ -1054,38 +1054,46 @@
 )%0A%7D)%0Aapp.post('/
-logout
+forgotPassword
 ', (req, res) =%3E
@@ -1109,33 +1109,144 @@
 nsole.log('/
-logout')%0A
+forgotPassword',req.body)%0A    res.json(TOKEN)%0A%7D)%0Aapp.post('/signIn', (req, res) =%3E %7B%0A    console.log('/signIn',req.body)
 %0A    res.jso
@@ -1243,26 +1243,29 @@
    res.json(
-%7B%7D
+TOKEN
 )%0A%7D)%0A%0A//ws%0Aw

add auth stub api