Giter VIP home page Giter VIP logo

Comments (10)

lpinca avatar lpinca commented on May 26, 2024

I cannot reproduce the issue:

const Primus = require('primus');
const http = require('http');
const fs = require('fs');

const server = http.createServer(function (req, res) {
  res.setHeader('Content-Type', 'text/html');
  fs.createReadStream(__dirname + '/index.html').pipe(res);
});

const primus = new Primus(server, {
  pathname: '/mycustompath/primus',
  transformer: 'engine.io'
});

primus.on('connection', function (spark) {
  console.log(spark.id, 'connected');
});

server.listen(3000, function () {
  console.log('listening on port 3000');
});
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <script src="/mycustompath/primus/primus.js"></script>
    <script>
      (function () {
        var primus = new Primus({ strategy: false });

        primus.on('open', function open() {
          console.log('open');
        });
      })();
    </script>
  </body>
</html>

Immagine 2021-07-13 111533

Did you rebuild the client?

from primus.

lpinca avatar lpinca commented on May 26, 2024

It does not matter, that is just where the Primus client is found.

const Primus = require('primus');
const http = require('http');
const fs = require('fs');

const server = http.createServer(function (req, res) {
  if (req.url === '/primus-client.js') {
    res.setHeader('Content-Type', 'text/javascript');
    fs.createReadStream(__dirname + '/primus-client.js').pipe(res);
    return;
  }

  res.setHeader('Content-Type', 'text/html');
  fs.createReadStream(__dirname + '/index.html').pipe(res);
});

const primus = new Primus(server, {
  pathname: '/mycustompath/primus',
  transformer: 'engine.io'
});

primus.save(__dirname + '/primus-client.js');

primus.on('connection', function (spark) {
  console.log(spark.id, 'connected');
});

server.listen(3000, function () {
  console.log('listening on port 3000');
});
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <script src="/primus-client.js"></script>
    <script>
      (function () {
        var primus = new Primus({ strategy: false });

        primus.on('open', function open() {
          console.log('open');
        });
      })();
    </script>
  </body>
</html>

from primus.

lpinca avatar lpinca commented on May 26, 2024

It means the Primus constructor is not found. Ensure that the client script it correctly loaded.

from primus.

lpinca avatar lpinca commented on May 26, 2024

I can't debug your code, sorry. That's up to you.

from primus.

lpinca avatar lpinca commented on May 26, 2024

You probably just have to save the client lib under the javascript folder and get it from there.

primus.save('/path/to/javascript/primus.js');
<script src="/path/to/javascript/primus.js"></script>

from primus.

lpinca avatar lpinca commented on May 26, 2024

That is a CORS issue because you are sending a cross origin request from https://app.autoscheduler.ai to https://api.autoscheduler.ai. See https://github.com/primus/primus#getting-started and https://github.com/socketio/engine.io#methods-1.

from primus.

lpinca avatar lpinca commented on May 26, 2024

Requests for primus/engine.io are not handled by express.

from primus.

lpinca avatar lpinca commented on May 26, 2024

No, server side.

from primus.

lpinca avatar lpinca commented on May 26, 2024

No, cors is not a valid primus option. It should eventually be origins but it depends on your architecture. Is https://api.autoscheduler.ai/ running primus? From the screenshots it seems to run a plain engine.io server. If so you should use the cors option as per https://github.com/socketio/engine.io#methods-1 and things might not work as you expect if you use a primus client to connect to it.

from primus.

lpinca avatar lpinca commented on May 26, 2024

I'm closing this. Let me know if it should stay open.

from primus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.