zabi.zamir

zabi.zamir

Member Since 3 Years Ago

Experience Points 670
Experience Level 1

4,330 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 4
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

18 Mar
3 years ago

zabi.zamir left a reply on Node.js Requests In Laravel

I managed to solve it by add this:

app.use(function(req, res, next) {
        res.header("Access-Control-Allow-Origin", "*");
        res.header("Access-Control-Allow-Headers", "X-Requested-With");
        res.header("Access-Control-Allow-Headers", "Content-Type");
        res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
        next();
    });

Thank you @premsaurav and @ohffs for your help.

zabi.zamir left a reply on Node.js Requests In Laravel

Thank you guys, the path worked, but now I get this error:

XMLHttpRequest cannot load https://domainname.com:3000/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://domainname.com' is therefore not allowed access.

Could you help me on this?

zabi.zamir left a reply on Node.js Requests In Laravel

I am not sure, but I assume so. I am using SSL so it request comes through port 443. I don't how to set route definition on node.js as I said before I am new to node.js. Could you provide example how to set route definition on node.js. Thanks

zabi.zamir left a reply on Node.js Requests In Laravel

I have not copied all code, I have app.listen which is working. I have already tried 'http://something:3000/login' but it gives me 404 error.

zabi.zamir left a reply on Node.js Requests In Laravel

@ohffs My request is going to PHP server(laravel) and route are checked against routes.php file. There is my code, it may clarify issue I am facing.

Clinet side:

$( document ).ready(function() {
    function connect_socket (token) {
    var socket = io( 'http://localhost:3000',{ 'sync disconnect on unload': true, query: 'token=' + token });
  
  socket.on('connect', function () {
    console.log('authenticated');
  }).on('disconnect', function () {
    console.log('disconnected');
  });
}

$(document).on("click", "#test_socket", function (e) {
   $.post('/login', {   
  }).done(function (result) {
    connect_socket(result.token);
  });
});

Server side (Node.js)

var app = require('express')();
var Redis = require('ioredis');
var redis = new Redis();

var jwtSecret ="hello";

app.post('/login', function (req, res) {

  var profile = {
    first_name: 'John',
    last_name: 'Doe',
    email: 'john@doe.com',
    id: 123
  };

  // we are sending the profile in the token
  var token = jwt.sign(profile, jwtSecret, { expiresInMinutes: 60*5 });

  res.json({token: token});
});

This express route referring to \login does not pick up on client side. That is my main issue. Any help is highly appreciated. Thanks

zabi.zamir left a reply on Node.js Requests In Laravel

As it explains in this example https://auth0.com/blog/2014/01/15/auth-with-socket-io/ I need to send a request to node.js server on my home page load which is in laravel. After that, on node.js server side jwt token will be generated and returned to the client side for socket.io authentication. The problem is that if I make a request to node.js route it brings error 500 as route does not exist in routes.php (laravel). I hope I clarified it a little bit. Thanks

zabi.zamir left a reply on Node.js Requests In Laravel

Thanks for reply, I have watched those series but I could not find answer to my issue. My main problem is how to make a request to node.js route but not to laravel route. I don't know if that is even possible as I am new to node.js. Thanks.

zabi.zamir started a new conversation Node.js Requests In Laravel

Hello everyone,

I am trying to implement socket.io authentication using the following example https://auth0.com/blog/2014/01/15/auth-with-socket-io/ . Currently I am using Laravel and Angular.js for my project and socket.io, node.js, redis for my chat application. I want to send a request to node.js server once laravel page loads. Is it doable? If yes, how to achieve that? Any help would be much appreciated . Thanks.

16 Mar
3 years ago

zabi.zamir left a reply on Socket.io Works Only On Localhost

@willvincent you a life saver. Your questions made me thinking and apparently port 3000 was closed to publicity. That was my problem. Now it is working fine from anywhere. Thank you very much. I couldn't do it without you.

15 Mar
3 years ago

zabi.zamir left a reply on Socket.io Works Only On Localhost

@supervip node sockets.js is running as it works on localhost. @veve286 I know that server ip is actual ip, domain name does not make a difference. I will try forever package after I will solve this issue. Do you have any more suggestion? Thanks

zabi.zamir left a reply on Socket.io Works Only On Localhost

@veve286 thanks for reply. Port 3000 is listening as I checked it via netstat -an and it work perfectly fine on localhost. Do you have any other suggestions? Thanks @supervip thanks for reply but I am not using forge. Do you have any other suggestions? Thanks

zabi.zamir left a reply on Socket.io Works Only On Localhost

@willvincent Thank you for your reply, I have changed my code to this:

<script type="text/javascript" src="http://[serverip]:3000/socket.io/socket.io.js"></script>
<script>
var socket = io( 'http://[serverip]:3000' );

console.log('check 1', socket.connected);
socket.on('connect', function() {
  console.log('check 2', socket.connected);
});

socket.on("connect", function () {  
    console.log("Connected!");
});

And now I get this error:

GET http://[serverip]:3000/socket.io/socket.io.js net::ERR_CONNECTION_TIMED_OUT

I assume that node.js server does not serve the file. I could not locate file manually, I could only locate node_modules/socket.io-client/socket.io.js but then I get timeout error as well.

Please help me as I his issue is driving me mad. I ma trying to solve it for a week already. Thanks

14 Mar
3 years ago

zabi.zamir left a reply on Step By Step Guide To Installing Socket.io And Broadcasting Events With Laravel 5.1

I used this code and everything works fine on localhost, but it does not work from external ip. This is the error I get:

GET http://serverip:3000/socket.io/?EIO=3&transport=polling&t=LDrVJCA Request.create @ socket.io.min.js:1Request @ socket.io.min.js:1XHR.request @ socket.io.min.js:1XHR.doPoll @ socket.io.min.js:1Polling.poll @ socket.io.min.js:1Polling.doOpen @ socket.io.min.js:1Transport.open @ socket.io.min.js:1Socket.open @ socket.io.min.js:1Socket @ socket.io.min.js:1Socket @ socket.io.min.js:1Manager.open.Manager.connect @ socket.io.min.js:2(anonymous function) @ socket.io.min.js:3 feedTest:1 XMLHttpRequest cannot load http://serverip:3000/socket.io/?EIO=3&transport=polling&t=LDrVJCA. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access. The response had HTTP status code 502.

Please help me anyone as I already search everywhere online I could not find working solution. Any help would be highly appreciated. Thanks

zabi.zamir started a new conversation Socket.io Works Only On Localhost

I am trying to implement sockets by following the tutorial https://laracasts.com/discuss/channels/general-discussion/step-by-step-guide-to-installing-socketio-and-broadcasting-events-with-laravel-51 . I got node.js running, reddis working and port 3000 is listening. I can get console messages on command line. Problem occurs when i try to emit anything to the client side. Sever side:

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('test-channel', function(err, count) {
});
redis.on('message', function(channel, message) {
    console.log('Message Recieved: ' + message);
    message = JSON.parse(message);
    io.emit(channel + ':' + message.event, message.data);
});
http.listen(3000, function(){
    console.log('Listening on Port 3000');
});

Client side:

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.7/socket.io.min.js"></script>
<script>
       /var socket = io('http://serverip:3000');
    socket.on("test-channel:App\\Events\\EventName", function(message){
        console.log("Working");
        // increase the power everytime we load test route
        $('#power').text(parseInt($('#power').text()) + parseInt(message.data.power));
    });

It works perfectly fine on locahost, but from external ip it gives me Access-Control-Allow-Origin 502 Error.

GET http://serverip:3000/socket.io/?EIO=3&transport=polling&t=LDrVJCA Request.create @ socket.io.min.js:1Request @ socket.io.min.js:1XHR.request @ socket.io.min.js:1XHR.doPoll @ socket.io.min.js:1Polling.poll @ socket.io.min.js:1Polling.doOpen @ socket.io.min.js:1Transport.open @ socket.io.min.js:1Socket.open @ socket.io.min.js:1Socket @ socket.io.min.js:1Socket @ socket.io.min.js:1Manager.open.Manager.connect @ socket.io.min.js:2(anonymous function) @ socket.io.min.js:3
feedTest:1 XMLHttpRequest cannot load http://serverip:3000/socket.io/?EIO=3&transport=polling&t=LDrVJCA. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access. The response had HTTP status code 502.

I also changed cdn socket.io.min.js and stored locally as few people suggested that. I have been trying every single suggestion and example available online but nothing helped. Any help would be much appreciated. Thanks