Skip to content
Snippets Groups Projects
Commit 603e7709 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Add XML response

parent 05947dff
No related branches found
No related tags found
1 merge request!2Issues/3
...@@ -3,6 +3,7 @@ var path = require('path') ...@@ -3,6 +3,7 @@ var path = require('path')
var cookieParser = require('cookie-parser') var cookieParser = require('cookie-parser')
var bodyParser = require('body-parser') var bodyParser = require('body-parser')
var csv = require('csv-express') var csv = require('csv-express')
var xml = require('xml')
var methodOverride = require('method-override') var methodOverride = require('method-override')
var libs = process.cwd() + '/libs/' var libs = process.cwd() + '/libs/'
......
var express = require('express') var express = require('express')
var router = express.Router() var router = express.Router()
var xml = require('xml')
var libs = process.cwd() + '/libs/' var libs = process.cwd() + '/libs/'
var log = require(libs + 'log')(module) var log = require(libs + 'log')(module)
...@@ -27,7 +27,7 @@ router.get('/data', function(req, res) { ...@@ -27,7 +27,7 @@ router.get('/data', function(req, res) {
}) })
}) })
router.get('/matriculas/:format?', function(req, res) { router.get('/matriculas.:format?', function(req, res) {
log.debug(req.query); log.debug(req.query);
tbl_name = "matriculas"; tbl_name = "matriculas";
...@@ -49,8 +49,13 @@ router.get('/matriculas/:format?', function(req, res) { ...@@ -49,8 +49,13 @@ router.get('/matriculas/:format?', function(req, res) {
'SELECT * FROM ' + tbl_name, true 'SELECT * FROM ' + tbl_name, true
).then(function(result) { ).then(function(result) {
log.debug(result); log.debug(result);
if (req.params.format) { if (req.params.format === 'csv') {
res.csv(result.data) res.csv(result.data)
} else if (req.params.format === 'xml') {
res.set('Content-Type', 'text/xml')
res.send(xml({
'result': result.data
}))
} }
else { else {
res.json({ res.json({
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
"method-override": "^2.3.3", "method-override": "^2.3.3",
"monetdb": "^1.1.2", "monetdb": "^1.1.2",
"nconf": "^0.6.x", "nconf": "^0.6.x",
"winston": "^0.8.x" "winston": "^0.8.x",
"xml": "^1.0.1"
}, },
"license": "MIT" "license": "MIT"
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment