-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WSS example ? #20
Comments
i'll have something soon that provides a (hopefully) nice and fast api for http, tls, websockets, templating, file serving, caching and middleware soon. it will be a separate module outside the "just" project on github but under "just-js" org for now. will let you know when i have something usable. |
following! |
@billywhizz any update on this? |
hi @gauravAit. actually yes! apologies to all for lack of communication but i have not been able to focus a lot of time on this over last couple months. i have been hacking away on it though and should be able to pull the various pieces together over next few days and get a new release out. i have a reasonably nice api now for http 1.1 servers and clients with tls and websocket support and from tests i have done performance on the techempower benchmarks should be pretty much the same even with a much nicer api. here's what the techempower code looks like now. much nicer than the pretty hideous PoC i put together for the benchmark last year! const stringify = require('@stringify')
const html = require('@html')
const cache = require('@cache')
const dns = require('@dns')
const postgres = require('@pg')
const justify = require('@http')
const socket = require('@socket')
const util = require('lib/util.js')
const config = require('tfb.config.js')
const { getIPAddress } = dns
const { createSocket } = socket
const { createServer, responses } = justify
const { SimpleCache } = cache
const { sprayer, sortByMessage, getUpdateQuery } = util
const { sjs, attr } = stringify
const maxQuery = 500
const maxRows = 10000
const spray = sprayer(maxQuery)
const message = 'Hello, World!'
const json = { message }
const extra = { id: 0, message: 'Additional fortune added at request time.' }
const getRandom = () => Math.ceil(Math.random() * maxRows)
const getCount = (qs = { q: 1 }) => (Math.min(parseInt((qs.q) || 1, 10), maxQuery) || 1)
const sJSON = sjs({ message: attr('string') })
const wJSON = sjs({ id: attr('number'), randomnumber: attr('number') })
async function main () {
const { db, fortunes, worlds, templates } = config
const sock = createSocket()
const ip = await getIPAddress(db.hostname)
await sock.connect(ip, db.port || 5432)
const pg = await postgres.createSocket(sock, db)
const getWorldById = await pg.compile(worlds)
const getFortunes = await pg.compile(fortunes)
const worldCache = new SimpleCache(id => getWorldById(id))
const template = html.load(templates.fortunes, templates.settings)
const getRandomWorld = () => getWorldById(getRandom())
const getRandomWorldCached = () => worldCache.get(getRandom())
const server = createServer()
.get('/plaintext', res => res.text(message))
.get('/json', res => res.utf8(sJSON(json), responses.json))
.get('/db', async res => res.utf8(wJSON(await getRandomWorld()), responses.json))
.get('/fortunes', async res => res.html(template.call(sortByMessage([extra, ...await getFortunes()]))))
.get('/cached-world', async (res, req) => res.json(await Promise.all(spray(getCount(req.query), getRandomWorldCached))))
.get('/query', async (res, req) => res.json(await Promise.all(spray(getCount(req.query), getRandomWorld))))
.get('/update', async (res, req) => {
const count = getCount(req.query)
const worlds = await Promise.all(spray(count, getRandomWorld))
const updateWorlds = await getUpdateQuery(count, pg)
await updateWorlds(...worlds.map(w => {
w.randomnumber = getRandom()
return [w.id, w.randomnumber]
}).flat())
res.json(worlds)
})
.listen('0.0.0.0', 8080)
}
main().catch(err => just.error(err.stack)) |
Hey,
can you please make example with secured websocket ?
something like in node/ws examples
The text was updated successfully, but these errors were encountered: