pemrouz / fero Goto Github PK
View Code? Open in Web Editor NEWlight, fast, scalable, streaming microservices made easy
light, fast, scalable, streaming microservices made easy
Hello and thanks for your fantastic work on fero
- Still trying to get around the correct peering options from the test examples - Would you have an example handy for using it in a scenario with remote peers/networks or feeding from DHT discovery, or anything with a fixed set of peers?
I'm having a hard time trying to figure out how to use Fero on my own.
For example, I'm trying to build a simple distributed user login system:
// server1.js
const fero = require('fero')
const users = []
const register = req => {
users.push(req.value)
return [200, 'ok']
}
const login = req => {
const { user, password } = req.value
if (users.find(u => user === u.user && password === u.password )) {
return [200, 'ok']
}
return [401, 'not authorized']
}
async function bs () {
const users = await fero('users', async req =>
req.type == 'LOGIN' ? login(req)
: req.type == 'REGISTER' ? register(req)
: [405, 'method not allowed'])
users.on('change')
.map(({ key, value }) => console.log(key, value))
}
bs()
.then(() => console.log('ready 1'))
// server2.js
const fero = require('fero')
async function bs () {
const users = await fero('users')
console.log('PEERS:', users.peers)
const data = await users.peers.send({
type: 'REGISTER',
key: 'foo',
value: {
user: 'foo',
password: '1234'
}
})
console.log('DATA:', data)
}
bs()
.then(() => console.log('ready 2'))
However, nothing happens, even though the peers are connected.
I'm sure there's something wrong, but I'm currently not able to make this work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.