This repository was archived by the owner on Mar 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (50 loc) · 1.69 KB
/
index.js
File metadata and controls
61 lines (50 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Entry Point
exports.handler = function( event, context ) {
"use strict";
var path = require('path'),
fs = require('fs'),
http = require('http'),
phantomDownloadPath = "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64-symbols.tar.bz2",
childProcess = require('child_process');
// Get the path to the phantomjs application
function getPhantomFileName(callback) {
var nodeModulesPath = path.join(__dirname, 'node_modules');
fs.exists(nodeModulesPath, function(exists) {
if (exists) {
callback(path.join(__dirname, 'node_modules','phantomjs', 'bin', 'phantomjs'));
}
else {
callback(path.join(__dirname, 'phantomjs'));
}
});
}
// Call the phantomjs script
function callPhantom(callback) {
getPhantomFileName(function(phantomJsPath) {
var childArgs = [
path.join(__dirname, 'phantomjs-script.js')
];
console.log('Calling phantom: ', phantomJsPath, childArgs);
var ls = childProcess.execFile(phantomJsPath, childArgs);
setTimeout(function () {
console.log('Timeout being called ...');
}, 1000);
ls.stdout.on('data', function (data) { // register one or more handlers
console.log(data);
GLOBAL.data = data;
});
ls.stderr.on('data', function (data) {
console.log('phantom error ---:> ' + data);
});
ls.on('exit', function (code) {
console.log('child process exited with code ' + code);
callback();
});
});
}
// Execute the phantom call and exit
callPhantom(function() {
//context.done();
context.done(null, {"hi":GLOBAL.data});
});
}