how do correctly the routing
Client:
controller
$scope.exportData = function () {
$http.get('/api/customers/excel/');
};
Server:
controller
var Customer = require('./customer.model');
var excelReport = require('excel-report');
var express = require('express');
var _ = require('lodash');
var fs = require('fs');
// Get list of customers
exports.index = function(req, res) {
Customer.find(function (err, customers) {
if(err) { return handleError(res, err); }
return res.json(200, customers);
});
};
//calling with index
exports.excel = function(req, res) {
console.log('test export');
console.log(__dirname + 'client/template.xlsx');
var template_file ='template.xlsx';
res.download(template_file);
});
};
index (index routes)
var express = require('express');
var controller = require('./customer.controller');
var router = express.Router();
router.get('/', controller.index);
router.get('/excel', controller.excel);
module.exports = router;
routes.
module.exports = function(app) {
// Insert routes below
app.use('/api/customers', require('./api/customer'));
app.use('/api/things', require('./api/thing'));
// All other routes should redirect to the index.html
app.route('/*')
.get(function(req, res) {
res.sendfile(app.get('appPath') + '/index.html');
});
}
i use generator-angular-fullstack for creating project to test
but I have the following error
GET http://localhost:9000/api/customers/excel/ 500
helpme please
Aucun commentaire:
Enregistrer un commentaire