Skip to content

Instantly share code, notes, and snippets.

@cianclarke
Created January 27, 2016 22:28
Show Gist options
  • Save cianclarke/5a17fa8e4554c9c3b88f to your computer and use it in GitHub Desktop.
Save cianclarke/5a17fa8e4554c9c3b88f to your computer and use it in GitHub Desktop.
semi-complete hello.js for barcode project
var soap = require('soap');
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
function helloRoute() {
var hello = new express.Router();
hello.use(cors());
hello.use(bodyParser());
hello.all('/', function(req, res) {
var barcode = req.query.barcode || req.body.barcode;
var wsdlUrl = 'http://www.searchupc.com/service/UPCSearch.asmx?wsdl';
soap.createClient(wsdlUrl, function(err, soapClient){
// we now have a soapClient - we also need to make sure there's no `err` here.
if (err){
return res.status(500).json(err);
}
soapClient.GetProduct({
upc : barcode,
accesstoken : '924646BB-A268-4007-9D87-2CE3084B47BC'
}, function(err, result){
if (err){
return res.status(500).json(err);
}
return res.json(result);
});
});
});
return hello;
}
module.exports = helloRoute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment