-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ed62aa
commit 07ec570
Showing
13 changed files
with
100 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = async (fastify, port, console) => { | ||
try { | ||
await fastify.listen({ port }); | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const fastify = require('fastify')(); | ||
const start = require('./start.js'); | ||
const handler = require('../ws-handler.js'); | ||
|
||
const setup = async (routing) => { | ||
fastify.register(async (fastify) => { | ||
fastify.get('*', { websocket: true }, ({ socket }) => { | ||
socket.on('message', (message) => | ||
handler({ routing, socket, console, message }) | ||
); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = async (routing, port, console) => { | ||
fastify.register(require('@fastify/websocket')); | ||
await setup(routing); | ||
await start(fastify, port, console); | ||
console.log('🔌 Fastify WS'); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
const { Server } = require('ws'); | ||
const handler = require('../ws-handler.js'); | ||
|
||
module.exports = (routing, port, console) => { | ||
const ws = new Server({ port }); | ||
ws.on('connection', (socket) => { | ||
socket.on('message', async (message) => | ||
handler({ routing, socket, console, message }) | ||
); | ||
}); | ||
console.log('🔌 Native WS'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const handler = async ({ routing, socket, console, message }) => { | ||
const send = (result) => { | ||
socket.send(JSON.stringify(result), { binary: false }); | ||
}; | ||
const obj = JSON.parse(message); | ||
const { name, method, args = [] } = obj; | ||
const entity = routing[name]; | ||
if (!entity) { | ||
send({ error: 'Entity not found' }); | ||
return; | ||
} | ||
const handler = entity[method]; | ||
if (!handler) { | ||
send({ error: 'Handler hot found' }); | ||
return; | ||
} | ||
try { | ||
const result = await handler(...args); | ||
send(result); | ||
} catch (err) { | ||
console.error(err); | ||
send({ error: 'Server error' }); | ||
} | ||
}; | ||
|
||
// TODO: unify and create http-handler.js | ||
module.exports = handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters