Skip to content

Instantly share code, notes, and snippets.

@jgchristopher
Created November 20, 2013 17:23
Show Gist options
  • Save jgchristopher/7567221 to your computer and use it in GitHub Desktop.
Save jgchristopher/7567221 to your computer and use it in GitHub Desktop.
Example of creating a simple web interface to allow testers to initiate some grunt commands.
"use strict";
var express = require('express'),
flash = require('connect-flash'),
path = require('path'),
cons = require('consolidate'),
grunt = require('grunt');
var app = express();
process.title = "test-data-admin";
app.engine('handlebars', cons.handlebars);
app.configure(function () {
app.set('views', __dirname + '/lib/views');
app.set('view engine', 'handlebars');
app.use(express.bodyParser());
app.use(express.cookieParser('sekret'));
app.use(express.session({ cookie: { maxAge: 60000 }}));
app.use(flash());
app.configure('development', function () {
app.use(express.static(path.resolve(__dirname, '..', 'static')));
});
});
app.configure('production', function () {
// Do not run this in production under any circumstances right now, unless you manually override this on the server
process.exit(1);
});
app.get('/test-data-admin', function (req, res) {
res.render('index', {messages: req.flash('info')});
});
app.get('/test-data-admin/refresh_db', function (req, res) {
grunt.tasks(["refresh_db", "load_default_users"], {}, function () {
req.flash('info', 'DB refreshed and test users loaded.');
res.redirect('/test-data-admin');
});
});
app.get('/test-data-admin/email_verification/:emailAddress', function (req, res) {
var emailAddress = req.params.emailAddress;
grunt.tasks(["email_verification_web:" + emailAddress], {}, function () {
res.send({error: false});
});
});
app.get('/*', function (req, res) {
res.render('index', {messages: req.flash('info')});
});
app.listen('8088');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment