Comments (4)
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.
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.
will let you know when i have something usable.
following!
from just.
@billywhizz any update on this?
from just.
Related Issues (20)
- Which V8 Version? HOT 1
- Tips on how to use external C/C++ modules
- just.library('http') return undefined (windows10 wsl2 ubuntu) HOT 8
- run on baremetal Raspberry Pi? HOT 1
- "Hello World" example HOT 9
- Lets Merge runtime-js and its kernel directly into this project HOT 1
- BIG ISSUE: WHERE CAN I SEND YOU MONEY HOT 7
- Mariadb Support HOT 4
- Next steps? We are all stuck at "Go"! HOT 7
- Documentation: The JustJS smol runtime Documentation. HOT 1
- PR: lib/snapshot.js (create, load, modify)
- Apache benchmark not working. HOT 2
- PR: cli api
- The Just js fundamentals and build instructions as a book
- Build failed with linker errors HOT 2
- avoid clock_gettime syscall by use vDSO HOT 1
- [Question] ESM Support? HOT 11
- EvalError: Code generation from strings disallowed for this context HOT 2
- Maintenance update? HOT 9
- Is there any way to add nodejs library ? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from just.