Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
94
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 = new Node({ hub: new NetworkHub('ws://tachy0n.com:5001/') })
  6.  
  7.     // print local information about your local node
  8.  
  9.     console.log('local address: ', await node.address())
  10.  
  11.     console.log('local configuration', JSON.stringify(await node.hub.configuration(), null, 2))
  12.  
  13.     // create a simple rest server.
  14.  
  15.     const server = node.rest.createServer()
  16.  
  17.     server.get('/', (req, res) => {
  18.  
  19.         console.log('server has request', req)
  20.  
  21.         res.send('hello world')        
  22.     })
  23.  
  24.     server.listen(80)
  25.  
  26.  
  27.     // fetch it
  28.  
  29.     const remote_address = 'x.0.0.0'
  30.  
  31.     const data = await node_b.rest.fetch(`rest://${remote_address}`).then(res => res.text())
  32.  
  33.     console.log(data)
  34. }
  35.  
  36. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement