@@ -10,34 +10,34 @@ var querystring = require('querystring');
1010
1111module . exports . translate = function ( authenticate , data , language , outputType , callback ) {
1212
13- // defaults for dev outside bluemix
14- var service_url = authenticate . translateConfig . service_url ;
15- var service_username = authenticate . translateConfig . service_username ;
16- var service_password = authenticate . translateConfig . service_password ;
13+ // defaults for dev outside bluemix
14+ var service_url = authenticate . translateConfig . service_url ;
15+ var service_username = authenticate . translateConfig . service_username ;
16+ var service_password = authenticate . translateConfig . service_password ;
17+
18+ // VCAP_SERVICES contains all the credentials of services bound to
19+ // this application. For details of its content, please refer to
20+ // the document or sample of each service.
21+ if ( process . env . VCAP_SERVICES ) {
22+ console . log ( 'Parsing VCAP_SERVICES' ) ;
23+ var services = JSON . parse ( process . env . VCAP_SERVICES ) ;
24+ //service name, check the VCAP_SERVICES in bluemix to get the name of the services you have
25+ var service_name = 'machine_translation' ;
26+
27+ if ( services [ service_name ] ) {
28+ var svc = services [ service_name ] [ 0 ] . credentials ;
29+ service_url = svc . url ;
30+ service_username = svc . username ;
31+ service_password = svc . password ;
32+ } else {
33+ console . log ( 'The service ' + service_name + ' is not in the VCAP_SERVICES, did you forget to bind it?' ) ;
34+ }
1735
18- // VCAP_SERVICES contains all the credentials of services bound to
19- // this application. For details of its content, please refer to
20- // the document or sample of each service.
21- if ( process . env . VCAP_SERVICES ) {
22- console . log ( 'Parsing VCAP_SERVICES' ) ;
23- var services = JSON . parse ( process . env . VCAP_SERVICES ) ;
24- //service name, check the VCAP_SERVICES in bluemix to get the name of the services you have
25- var service_name = 'machine_translation' ;
26-
27- if ( services [ service_name ] ) {
28- var svc = services [ service_name ] [ 0 ] . credentials ;
29- service_url = svc . url ;
30- service_username = svc . username ;
31- service_password = svc . password ;
3236 } else {
33- console . log ( 'The service ' + service_name + ' is not in the VCAP_SERVICES, did you forget to bind it? ') ;
37+ console . log ( 'No VCAP_SERVICES found in ENV, using defaults for local development ' ) ;
3438 }
3539
36- } else {
37- console . log ( 'No VCAP_SERVICES found in ENV, using defaults for local development' ) ;
38- }
39-
40- var auth = 'Basic ' + new Buffer ( service_username + ':' + service_password ) . toString ( 'base64' ) ;
40+ var auth = 'Basic ' + new Buffer ( service_username + ':' + service_password ) . toString ( 'base64' ) ;
4141
4242 var request_data = {
4343 'txt' : data ,
0 commit comments