'use strict';

var joblint = require('joblint');

module.exports = defineController;

function defineController (app) {
    app.post('/ws', requireUrlEncodedPostBody, requireUnemptyJobSpec, function (req, res) {
        res.jsonp(joblint(req.body.spec));
    });
    app.all('/ws', function (req, res) {
        return res.jsonp(405, {
            error: 'Method not allowed, POST request expected'
        });
    });
}

function requireUrlEncodedPostBody (req, res, next) {
    if (req.headers['content-type'] !== 'application/x-www-form-urlencoded') {
        return res.jsonp(400, {
            error: 'Request must have a content-type of "application/x-www-form-urlencoded"'
        });
    }
    next();
}

function requireUnemptyJobSpec (req, res, next) {
    if (!req.body.spec || !req.body.spec.trim()) {
        return res.jsonp(400, {
            error: 'Spec must be a non-empty string'
        });
    }
    next();
}

@@ -109,24 +109,223 @@
 ler (app) %7B%0A
+    app.all('/ws', function (req, res, next) %7B%0A        res.header('Access-Control-Allow-Origin', '*');%0A        res.header('Access-Control-Allow-Headers', 'X-Requested-With');%0A        next();%0A    %7D);%0A
     app.post

Enable CORS