Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Node, NetworkHub } from 'smoke-node'
  2.  
  3. async function main() {
  4.  
  5.     const node_a = new Node({ hub: new NetworkHub('ws://tachy0n.com:5001/') })
  6.  
  7.     const node_b = new Node({ hub: new NetworkHub('ws://tachy0n.com:5001/') })
  8.  
  9.     const node_a_address = await node_a.address()
  10.  
  11.     // get the address of this node on the virtual network
  12.  
  13.     console.log('node_a',  await node_a.address())
  14.  
  15.     console.log('node_b',  await node_a.address())
  16.  
  17.     console.log('node_a_config', JSON.stringify(await node_a.hub.configuration(), null, 2))
  18.  
  19.     console.log('node_b_config', JSON.stringify(await node_a.hub.configuration(), null, 2))
  20.  
  21.     // create a simple rest server.
  22.  
  23.     const server = node_a.rest.createServer()
  24.  
  25.     server.get('/', (req, res) => {
  26.  
  27.         res.send('response from node_a')        
  28.     })
  29.  
  30.     server.listen(80)
  31.  
  32.  
  33.     // fetch it
  34.  
  35.     const data = await node_b.rest.fetch(`rest://${node_a_address}`).then(res => res.text())
  36.  
  37.     console.log(data)
  38. }
  39.  
  40. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement