node.js - Is it possible to return files for server methods in hapi -
I try to use server.method for
reply.file () I'm doing (), but it says that there is no
file in my
next function:
debug: happy , Internal, implementation, error type error: unwanted error: object function (mistake, result) {methodNext (fault, result, blank, {msec: timer.elapsed (), error: err}); } There is no method 'file on child process / user / user / work / dave / export.js 37:12. & Lt; Anonymous & gt; Child Process Amit (Events .JS: 98: 17) Process (/Users / User / Work / Dave / Node_Module / WebShot / Lib / Weizot.JSAJ 21: 9) Child Process._hand.onexit (child_process.js: 810: 12) I have the following:
server.method ('getexport', function ( Reform, Query Paramá, Host URI, Next) (next.file (File Path, {// Download as Attachment Mode: 'Attachment'});}); Instance.server.route ({method: 'GET', path: '/ export', config: {handler: function (req, answer) {var uri = req.server.info.uri; server.methods.getExport (req ). P.M., Ric. Query, Yuri, Answer);}}}); Is this possible?
I'm using hpi v6.9.
When you call the method, you have to pass the callback method.
Your code is working:
var hapi = require ('hapi'), server = new hapi.Server ('0.0.0.0', 5000) ; Server.method ('getExport', function (Reqormam, QuickParam, Host Yuri, Answer, Next) {// ... reply.file ('/ tmp / test.js', {// Download as an attachment mode Do: 'attachment'}); forthcoming ();}); Server.route ({method: 'GET', path: '/ export', config: {handler: function (req, answer) {var uri = req.server.info.uri; server.methods.getExport (req.params ), Req.query, uri, reply, work () {console.log ('run');})}}}}); Server.start () I would suggest not to use a server method for it, it seems that overwork to answer with the file, if possible, I also recommend upgrading to version.
Comments
Post a Comment