Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. var https = require('https');
  2.  
  3. var express = require('express');
  4. var handlebars = require('express-handlebars')
  5. .create({ defaultLayout:'main' });
  6.  
  7. var app = express();
  8. app.engine('handlebars', handlebars.engine);
  9. app.set('view engine', 'handlebars');
  10. app.set('port', process.env.PORT || 3000);
  11. app.set('ip', process.env.IP);
  12.  
  13. var options = {
  14. hostname: 'public-api.wordpress.com',
  15. path: '/rest/v1.1/sites/somesite.wordpress.com/posts/16',
  16. method: 'GET'
  17. };
  18.  
  19. app.get('/test', function(req, res) {
  20. https.request(options, function(restRes) {
  21. console.log('STATUS: ' + restRes.statusCode);
  22. res.render('home', { "title": "Test" }); // This code works.
  23. restRes.on('data', function (jsonResult) {
  24. // res.render('home', { "title": "Test" }); This code (after removing the line above) does not work.
  25. console.log('BODY: ' + jsonResult);
  26. });
  27. }).end();
  28. });
  29.  
  30. app.listen(app.get('port'), app.get('ip'), function(){
  31. console.log( 'Express started on http://' + app.get('ip') + ": " +
  32. app.get('port') + '; press Ctrl-C to terminate.' );
  33. });
  34.  
  35. Error: Can't set headers after they are sent.
  36. at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:331:11)
  37. at ServerResponse.header (/home/ubuntu/workspace/node_modules/express/lib/response.js:718:10)
  38. at ServerResponse.send (/home/ubuntu/workspace/node_modules/express/lib/response.js:163:12)
  39. at res.render.done (/home/ubuntu/workspace/node_modules/express/lib/response.js:957:10)
  40. at Immediate._onImmediate (/home/ubuntu/workspace/node_modules/express-handlebars/lib/utils.js:26:13)
  41. at processImmediate [as _immediateCallback] (timers.js:374:17)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement