#!/bin/sh

set -e

cat > /etc/apache2/conf-enabled/passenger-nodejs.conf <<EOT
Alias /testnodejs /var/www/testnodejs/public
<Location /testnodejs>
  PassengerBaseURI /testnodejs
  PassengerAppRoot /var/www/testnodejs
</Location>
EOT

mkdir /var/www/testnodejs
mkdir /var/www/testnodejs/public
mkdir /var/www/testnodejs/tmp
cat > /var/www/testnodejs/app.js <<EOT
var http = require('http');
var server = http.createServer(function(req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end("hello world\n");
});
server.listen(3000);
EOT
chown -R www-data:www-data /var/www/testnodejs

a2enmod passenger
service apache2 reload

$(dirname $0)/expect-hello-world http://localhost/testnodejs/
