<commit_before>
var http = require( 'http' ),
    url = require( 'url' ),
    request = require( 'request' ),
    express = require( 'express' ),
    MailChimpAPI = require( 'mailchimp' ).MailChimpAPI,
    config = require( './lib/config' ),
    FB = require( './lib/fb' ),
    fetchData = require( './lib/data' ).fetchAll,
    app = module.exports = express(),
    data = {},
    people = require( './lib/people' );

try
{
    var mailchimp = new MailChimpAPI( config.MAILCHIMP.API_KEY, { secure: true } );
}
catch( e )
{
    console.error( '[ERROR] Can\'t connect to MailChimp', e.message );
}

function refreshData()
{
    FB.__connect( function( FB )
    {
        accessToken = FB.getAccessToken();

        fetchData( FB, function( err, results )
        {
            data.albums = results.albums;
            data.events = results.events;
        } );
    } );

    setTimeout( refreshData, 60 * 15 * 100 );
}

refreshData();

app.enable( 'trust proxy' );

app.set( 'views', __dirname + '/views' );
app.engine( 'ejs', require( 'ejs-locals' ) );
app.locals._layoutFile = '/layout.ejs';
app.set( 'view engine', 'ejs' );

app.use( express.logger() );
app.use( express.compress() );
app.use( express.bodyParser() );

app.get( '/', function( req, res )
{
    res.render( 'home', {
        title: 'Home',
        events: data.events,
        page: 'home'
    } );
} );

app.get( '/events', function( req, res )
{
    res.render( 'events', {
        title: 'Events',
        events: data.events,
        page: 'events'
    } );
} );

app.get( '/people', function( req, res )
{
    res.render( 'people', {
        title: 'People',
        people: people,
        page: 'people'
    } );
} );

app.get( '/gallery', function( req, res )
{
    res.render( 'gallery', {
        title: 'Gallery',
        albums: data.albums,
        page: 'gallery'
    } );
} );

app.get( '/album/:id', function( req, res )
{
    var id = req.params.id,
        album = data.albums.findById( id );

    if( !album )
    {
        res.redirect( '/gallery' );
        return;
    }

    res.render( 'album', {
        title: album.name,
        album: album,
        page: 'gallery'
    } );
} );


app.post( '/subscribe', function( req, res )
{
    var email = req.body.email;

    if( !mailchimp )
    {
        res.json( 500, { status: 'error', error: 'Mailing list server down.' } );
        return;
    }

    if( !email )
    {
        res.json( 500, { status: 'error', error: 'No e-mail supplied.' } );
    }

    if( email && email.indexOf( '@' ) > 0 )
    {
        // Send an error if MailChimp doesn't answer after 10 seconds.
        var timeout = setTimeout( function()
        {
            res.json( 500, { status: 'error', error: 'Mailing list server didn\'t respond.' } );

        }, 10 * 1000 );

        mailchimp.listSubscribe(
            {
                id: config.MAILCHIMP.LIST_ID,
                email_address: email,
                email_type: 'html',
                update_existing: true,
                // double_optin: '?'
                // send_welcome: '?'
            },
            function( err, response )
            {
                clearTimeout( timeout );
                
                if( err )
                {
                    res.json( 500, { status: 'error', error: err.error } );
                }
                else
                {
                    res.json( 200, { status: 'subscribed', message: 'Ok! Please check your e-mail' } );
                }
            }
        );
    }
    else
    {
        res.json( 500, { status: 'error', error: 'Invalid e-mail address.' } );
    }
} );

app.use( express.static( __dirname + '/public' ) );

if( !module.parent )
{
    var port = process.env.PORT || 3000;
    
    app.listen( port );
    console.log( 'Express app started on port ' + port );
}
<commit_msg>Better success message.<commit_after>
var http = require( 'http' ),
    url = require( 'url' ),
    request = require( 'request' ),
    express = require( 'express' ),
    MailChimpAPI = require( 'mailchimp' ).MailChimpAPI,
    config = require( './lib/config' ),
    FB = require( './lib/fb' ),
    fetchData = require( './lib/data' ).fetchAll,
    app = module.exports = express(),
    data = {},
    people = require( './lib/people' );

try
{
    var mailchimp = new MailChimpAPI( config.MAILCHIMP.API_KEY, { secure: true } );
}
catch( e )
{
    console.error( '[ERROR] Can\'t connect to MailChimp', e.message );
}

function refreshData()
{
    FB.__connect( function( FB )
    {
        accessToken = FB.getAccessToken();

        fetchData( FB, function( err, results )
        {
            data.albums = results.albums;
            data.events = results.events;
        } );
    } );

    setTimeout( refreshData, 60 * 15 * 100 );
}

refreshData();

app.enable( 'trust proxy' );

app.set( 'views', __dirname + '/views' );
app.engine( 'ejs', require( 'ejs-locals' ) );
app.locals._layoutFile = '/layout.ejs';
app.set( 'view engine', 'ejs' );

app.use( express.logger() );
app.use( express.compress() );
app.use( express.bodyParser() );

app.get( '/', function( req, res )
{
    res.render( 'home', {
        title: 'Home',
        events: data.events,
        page: 'home'
    } );
} );

app.get( '/events', function( req, res )
{
    res.render( 'events', {
        title: 'Events',
        events: data.events,
        page: 'events'
    } );
} );

app.get( '/people', function( req, res )
{
    res.render( 'people', {
        title: 'People',
        people: people,
        page: 'people'
    } );
} );

app.get( '/gallery', function( req, res )
{
    res.render( 'gallery', {
        title: 'Gallery',
        albums: data.albums,
        page: 'gallery'
    } );
} );

app.get( '/album/:id', function( req, res )
{
    var id = req.params.id,
        album = data.albums.findById( id );

    if( !album )
    {
        res.redirect( '/gallery' );
        return;
    }

    res.render( 'album', {
        title: album.name,
        album: album,
        page: 'gallery'
    } );
} );


app.post( '/subscribe', function( req, res )
{
    var email = req.body.email;

    if( !mailchimp )
    {
        res.json( 500, { status: 'error', error: 'Mailing list server down.' } );
        return;
    }

    if( !email )
    {
        res.json( 500, { status: 'error', error: 'No e-mail supplied.' } );
    }

    if( email && email.indexOf( '@' ) > 0 )
    {
        // Send an error if MailChimp doesn't answer after 10 seconds.
        var timeout = setTimeout( function()
        {
            res.json( 500, { status: 'error', error: 'Mailing list server didn\'t respond.' } );

        }, 10 * 1000 );

        mailchimp.listSubscribe(
            {
                id: config.MAILCHIMP.LIST_ID,
                email_address: email,
                email_type: 'html',
                update_existing: true,
                // double_optin: '?'
                // send_welcome: '?'
            },
            function( err, response )
            {
                clearTimeout( timeout );

                if( err )
                {
                    res.json( 500, { status: 'error', error: err.error } );
                }
                else
                {
                    res.json( 200, { status: 'subscribed', message: 'Thanks! Please check your e-mail.' } );
                }
            }
        );
    }
    else
    {
        res.json( 500, { status: 'error', error: 'Invalid e-mail address.' } );
    }
} );

app.use( express.static( __dirname + '/public' ) );

if( !module.parent )
{
    var port = process.env.PORT || 3000;
    
    app.listen( port );
    console.log( 'Express app started on port ' + port );
}

{'fraction_non_alphanumeric': 0.16374724276631633, 'fraction_numerical': 0.009861165174516674, 'mean_word_length': 1.7597565341926245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '837624', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2444, 'n_words': 592}