Reputation: 11
I've set up an API with nodejs express for a real-time chat application. For it to be real-time I am using primus but I'm currently stuck at trying to connect primus to my frontend.
I have a folder structure for the whole backend and then another folder structure for my frontend. So they are both separate.
Here I connect the server to Primus
var server = http.createServer(app);
const primus = require('../primus/live').go(server);
This then goes as you can see to the folder primus with a file live.js
//BACKEND
const Primus = require('primus');
let go = (server) => {
let primus = new Primus(server, {/* options */});
primus.on('connection', (spark) => {
console.log('Received spark 🔥');
});
}
module.exports.go = go;
Now in my frontend, I am trying to call Primus via the script tag
//FRONTEND
<script src="http://localhost:3000/primus/live.js"></script>
but this just gives me a 404 Not Found error. Also when I just try to connect through this in my browser it doesn't work. So I am unsure what my problem here is. Any ideas?
Upvotes: 0
Views: 177
Reputation: 611
https://github.com/primus/primus#how-do-i-use-primus-with-express
make sure to call .listen
on the http server, not the Express server
Upvotes: 0