A
A
alex_gamescripts2020-11-29 15:23:32
CORS
alex_gamescripts, 2020-11-29 15:23:32

Socket issue. How to fix?

When running the server.js script. His code:

var http = require('http').Server();
var io = require('socket.io')(http);
var Redis = require('ioredis');

var redis = new Redis();
redis.subscribe('news-action');
redis.on('message', function(channel, message){
  console.log('Message recieved:' + message);
  console.log('Channel:' + channel);
  message = JSON.parse(message);
  io.emit(channel + ':' + message.event, message.data);
});

http.listen(3000, function(){
  console.log('Listening on Port: 3000')
});


vue component:
<template>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-12">
                <line-chart :chart-data="data" :height="100" :options="{responsive:true, maintainAspectRation: true}"></line-chart>
                <input type="checkbox" v-model="realtime"> realtime
                <input type="text" v-model="label">
                <input type="text" v-model="sale">
                <button @click="sendData"class="btn btn-primary">Обновить</button>
            </div>
        </div>
    </div>
</template>

<script>
    import LineChart from './LineChart.js'
    export default {
        components:{
                LineChart
            },
        data: function(){
            
            return{
                data: [],
                realtime: false,
                label:"",
                sale: 500
            } 
        },
        mounted() {
            var socket = io('http://cash3x.site:3000');
            socket.on("news-action:App\\Events\\NewEvent", function(data){
               this.data = data.result;
            }.bind(this));
            this.update()
        },
        methods: {
            update: function(){
            	 
                axios.get('/start/socket-chart').then((response) => {
                	this.data = response.data
                	
                }) 
            },
            sendData: function(){
                axios({
                    method: 'get',
                    url: '/start/socket-chart',
                    params: {label: this.label, sale: this.sale, realtime: this.realtime}
                }).then((response) => {
                    this.data = response.data
                    
                }) 

            }
        }
    }
</script>


An error pops up:
Access to XMLHttpRequest at ' cash3x.site:3000/socket.io/?EIO=4&transport=pollin... ' from origin 'ht.


Please tell me how to fix. Project in laravel. Link to cash3x.site/start

5fc3924304949949060087.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sanes, 2020-11-29
@Sanes

CORS says nothing?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question