Giter VIP home page Giter VIP logo

Comments (4)

billywhizz avatar billywhizz commented on August 25, 2024 16

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.

from just.

billywhizz avatar billywhizz commented on August 25, 2024 13

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))

from just.

tomByrer avatar tomByrer commented on August 25, 2024

will let you know when i have something usable.

following!

from just.

gauravAit avatar gauravAit commented on August 25, 2024

@billywhizz any update on this?

from just.

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.