I'm currently using expressJS to make a navigation for a nodeJS server and spookyJS for testing and I'd like to know if following code could work.
When a user visits http://localhost:3131/tests he sees a html site. This is working perfectly.
Example Code:
app.get('/tests', function (req, res)
{
res.render('tests.html');
});
When a user visits http://localhost:1337/tests/start the spookyJS tests should start but this isn't the case.
Example Code:
app.get('/tests/start', function (req, res)
{
try {
var Spooky = require('spooky');
} catch (e) {
var Spooky = require('../../lib/spooky');
}
var spooky = new Spooky({
casper: {
logLevel: 'debug',
verbose: true
}
}, function (err) {
if (err) {
e = new Error('Failed to initialize SpookyJS');
e.details = err;
throw e;
}
spooky.on('error', function (e) {
console.error(e);
}); ......
The code above isn't the full code it's just to give you an insight how I'd like to do it. Is it possible to do it this way with expressJS?
I have made another little example which works. The tests are starting when I navigate to an nodeJS server in my browser like in following example http://localhost:4141
var httpServer = require('http').createServer(function(req, response){
try {
var Spooky = require('spooky');
} catch (e) {
var Spooky = require('../../lib/spooky');
}
var spooky = new Spooky({
casper: {
logLevel: 'debug',
verbose: true
}
.
.
.
.
});
httpServer.listen(1337);
Why is it working when I use a normal nodeJS Server without navigation but with the expressJS navigation it isn't working? Thank you for your help, Alex