Add "Connect Logux to other HTTP server"
mrdimidium opened this issue · 3 comments
Hey. Thank you for what you're doing.,
I needed to attach Logux to my core HTTP server. This may be necessary, for example, on Heroku -- it only issues one port.
After read the source code, I found the server option, and was able to configure what I need.
Here is my code where it works:
server.js
:
const http = require('http');
const express = require('express');
const { Server: LoguxServer } = require('@logux/server');
const staticServer = express()
.use((req, res) => res.sendFile(INDEX) )
.listen(PORT, () => console.log(`Listening on ${ PORT }`));
const server = http.createServer(staticServer.callback());
const wsServer = new LoguxServer(
LoguxServer.loadOptions(process, {
server,
subprotocol: '1.0.0',
supports: '1.x',
root: __dirname,
}),
);
wsServer.auth(async (userId, token) => {
return true;
});
server.listen(8080);
wsServer.listen();
client.js
:
const createStore = createLoguxCreator({
server: window.location.origin.replace(/^http/i, 'ws'),
/* ... */
});
This is not obvious enough, but it may be necessary for many. Can we add example to the docs or an example to the repository?
You didn’t send PR for the previous issue report ;)
This is not obvious enough, but it may be necessary for many.
Yeap, it could be an interesting idea to just replace the protocol. Send PR (do not forget to think about development mode where you need to also change port)
Do you want to send PR for server
option too?