Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var https = require('https');
- var express = require('express');
- var handlebars = require('express-handlebars')
- .create({ defaultLayout:'main' });
- var app = express();
- app.engine('handlebars', handlebars.engine);
- app.set('view engine', 'handlebars');
- app.set('port', process.env.PORT || 3000);
- app.set('ip', process.env.IP);
- var options = {
- hostname: 'public-api.wordpress.com',
- path: '/rest/v1.1/sites/somesite.wordpress.com/posts/16',
- method: 'GET'
- };
- app.get('/test', function(req, res) {
- https.request(options, function(restRes) {
- console.log('STATUS: ' + restRes.statusCode);
- res.render('home', { "title": "Test" }); // This code works.
- restRes.on('data', function (jsonResult) {
- // res.render('home', { "title": "Test" }); This code (after removing the line above) does not work.
- console.log('BODY: ' + jsonResult);
- });
- }).end();
- });
- app.listen(app.get('port'), app.get('ip'), function(){
- console.log( 'Express started on http://' + app.get('ip') + ": " +
- app.get('port') + '; press Ctrl-C to terminate.' );
- });
- Error: Can't set headers after they are sent.
- at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:331:11)
- at ServerResponse.header (/home/ubuntu/workspace/node_modules/express/lib/response.js:718:10)
- at ServerResponse.send (/home/ubuntu/workspace/node_modules/express/lib/response.js:163:12)
- at res.render.done (/home/ubuntu/workspace/node_modules/express/lib/response.js:957:10)
- at Immediate._onImmediate (/home/ubuntu/workspace/node_modules/express-handlebars/lib/utils.js:26:13)
- at processImmediate [as _immediateCallback] (timers.js:374:17)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement