Commit af9913c24c8aaaa1a6838867a79f9e28356c608f
1 parent
974fcc3f
Exists in
master
and in
4 other branches
Translate routes corrections
Showing
2 changed files
with
21 additions
and
1 deletions
Show diff stats
translate-api/controllers/translate.js
@@ -12,7 +12,7 @@ var shortid = require('shortid') | @@ -12,7 +12,7 @@ var shortid = require('shortid') | ||
12 | , amqp = require('../helpers/amqpManager') | 12 | , amqp = require('../helpers/amqpManager') |
13 | , error = require('../helpers/error'); | 13 | , error = require('../helpers/error'); |
14 | 14 | ||
15 | -exports.translate = function(req, res) { | 15 | +exports.translate = function(req, res, next) { |
16 | if (!req.body.text) | 16 | if (!req.body.text) |
17 | return error.badRequest('The text key is missing.', next); | 17 | return error.badRequest('The text key is missing.', next); |
18 | 18 | ||
@@ -29,3 +29,22 @@ exports.translate = function(req, res) { | @@ -29,3 +29,22 @@ exports.translate = function(req, res) { | ||
29 | }); | 29 | }); |
30 | }); | 30 | }); |
31 | }; | 31 | }; |
32 | + | ||
33 | +// TEMPORARY | ||
34 | +exports.translateURL = function(req, res, next) { | ||
35 | + if (!req.param('text')) | ||
36 | + return error.badRequest('The text param is missing.', next); | ||
37 | + | ||
38 | + var id = shortid.generate(); | ||
39 | + var text = req.param('text').toString('utf8'); | ||
40 | + | ||
41 | + amqp.sendToQueue(text, id,'texts', false, res, function(err) { | ||
42 | + if (err) | ||
43 | + return error.internalError('An internal communication error has occurred.', next); | ||
44 | + amqp.receiveFromQueue(id, 'translations', false, res, function(err, message) { | ||
45 | + if (err) | ||
46 | + return error.internalError('An internal communication error has occurred.', next); | ||
47 | + res.status(200).send(message); | ||
48 | + }); | ||
49 | + }); | ||
50 | +}; |
translate-api/routes/translate.js
@@ -12,5 +12,6 @@ var express = require('express') | @@ -12,5 +12,6 @@ var express = require('express') | ||
12 | */ | 12 | */ |
13 | router | 13 | router |
14 | .post('/', translateController.translate) | 14 | .post('/', translateController.translate) |
15 | + .get('/', translateController.translateURL) // TEMPORARY | ||
15 | 16 | ||
16 | module.exports = router; | 17 | module.exports = router; |