Reputation: 8376
What I currently have is this script:
var phantom = require('phantom');
phantom.create(function(phantomInstance) {
phantomInstance.createPage(function(page) {
page.set('paperSize', {
format: 'A4',
orientation: 'portrait',
margin: '1cm'
});
page.open('https://blablabla.c9.io/pdf/' + data._id + data.querystring, function(status) {
page.render('client/pdf/' + data._id + '.pdf', function() {
phantomInstance.exit();
});
});
});
});
I read in Phantom.js docs that page.open
's first param has to be absolute URL. It's not very comfortable since I have two environments that have this script running (one dev on Cloud9 IDE, one prod on VPS).
Is there a better way to deal with this restriction, and is there a way to operate relative URLs without having URL base managed by hand (e.g. page.open(baseUrl + '...', ...)
)?
I use Express over Node.js server on both environments, if it helps.
Upvotes: 0
Views: 471
Reputation: 61892
No, and I don't see any considerable problems with generating your url on the fly (e.g. page.open(baseUrl + '...', ...)
).
You could create your own little wrapper, but will need to feed the baseUrl and relative path into it somehow which might make your life a little easier in the short term, but might be counterproductive in the long term when you need to refactor.
Upvotes: 1