Skip to content

Instantly share code, notes, and snippets.

@kianenigma
Last active May 8, 2017 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kianenigma/68977ee67acb9405a1fba9b685f05c2e to your computer and use it in GitHub Desktop.
Save kianenigma/68977ee67acb9405a1fba9b685f05c2e to your computer and use it in GitHub Desktop.
const express = require('express')
const XYZ = require('xyz-core')
const app = express()
const EXPRES_PORT = 4001
// setup xyz
const front = new XYZ({
selfConf: {
name: 'front.ms',
host: '127.0.0.1',
// all nodes will connect to seed node which is Client service
seed: ['127.0.0.1:5000']
transport: [{type: 'HTTP', port: 4000}],
logLevel: 'verbose'
}
})
// setup express app
app.post('/service', function (req, res) {
front.call({
servicePath: req.query['service_path']
}, (err, body) => {
res.json({err: err, body: body})
})
})
// note that xyz HTTP transport is listening on port 4000
// and express on port 4001
app.listen(EXPRES_PORT, function () {
// use xyz's logger
front.logger.info(`EXPRESS :: Front app listening on port ${EXPRES_PORT}!`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment