<commit_before>class Controller
    constructor: (@app) ->
        @_buildControllers()

        # sifelse.co.uk -> enactuslse.co.uk
        @_redirectSIFE()

        # Index
        @app.get '/', @controllers['home']['index']

        # Contact us
        if process.env.MAILGUN_API_KEY?
            @app.post '/contact-us', (req, res) =>
                @controllers['contact-us']['postIndex'](req, res, @)

        # Other pages
        @app.get '/:controller/:action?', (req, res) =>
            # Find controller and return 404 if it is not found
            controller = @routes[req.params.controller] ? @_notFound req, res
            action = controller.actions?[req.params.action]
            currentTitle = action?.title ? controller.title

            # Set metadata
            @_setTitle res, currentTitle
            @_setBreadcrumbs res, currentTitle, req.params.action ? req.params.controller, 
                            [title: controller.title, slug: req.params.controller] if action?

            req.params.action ?= 'index'

            # Call controller if it exists
            if @controllers[req.params.controller]?[req.params.action]?
                @controllers[req.params.controller][req.params.action] req, res, @

            @_render res, "#{req.params.controller}/#{req.params.action}"

        @app.use @_notFound

    _setTitle: (res, title) ->
        res.locals.page.title = "#{title} - #{res.locals.page.title}"

    _setBreadcrumbs: (res, title, slug, location) ->
        res.locals.current =
            title: title
            slug: slug
            location: location

    _render: (res, template) ->
        res.render template, {}, (error, html) =>
            return @_notFound false, res if error
            res.end html

    _buildControllers: ->
        @routes = @app.get('routes')
        @controllers = 
            'home': require './home.coffee'
            'contact-us': require './contact.coffee'

    _redirectSIFE: ->
        @app.all '/*', (req, res, next) =>
            res.redirect 301, '//enactuslse.co.uk' if req.header('host').match /sifelse/i
            next()

    _notFound: (req, res, next) ->
        res.locals.page.title = "Oops, we can't find what you are looking for! - #{res.locals.page.title}"
        res.status 404
        res.render '404',  layout: '_layouts/blank'

module.exports = (app) ->
    new Controller app<commit_msg>Added redirect for CDN; Coffeelint'd<commit_after>class Controller
    constructor: (@app) ->
        @_buildControllers()

        # cdn.enactuslse.co.uk or sifelse.co.uk -> enactuslse.co.uk
        @_redirects()

        # Index
        @app.get '/', @controllers['home']['index']

        # Contact us
        if process.env.MAILGUN_API_KEY?
            @app.post '/contact-us', (req, res) =>
                @controllers['contact-us']['postIndex'](req, res, @)

        # Other pages
        @app.get '/:controller/:action?', (req, res) =>
            # Find controller and return 404 if it is not found
            controller = @routes[req.params.controller] ? @_notFound req, res
            action = controller.actions?[req.params.action]
            currentTitle = action?.title ? controller.title

            # Set metadata
            @_setTitle res, currentTitle
            @_setBreadcrumbs res, currentTitle, req.params.action ? req.params.controller,
                            [title: controller.title, slug: req.params.controller] if action?

            req.params.action ?= 'index'

            # Call controller if it exists
            if @controllers[req.params.controller]?[req.params.action]?
                @controllers[req.params.controller][req.params.action] req, res, @

            @_render res, "#{req.params.controller}/#{req.params.action}"

        @app.use @_notFound

    _setTitle: (res, title) ->
        res.locals.page.title = "#{title} - #{res.locals.page.title}"

    _setBreadcrumbs: (res, title, slug, location) ->
        res.locals.current =
            title: title
            slug: slug
            location: location

    _render: (res, template) ->
        res.render template, {}, (error, html) =>
            return @_notFound false, res if error
            res.end html

    _buildControllers: ->
        @routes = @app.get('routes')
        @controllers =
            'home': require './home.coffee'
            'contact-us': require './contact.coffee'

    _redirects: ->
        @app.all '/*', (req, res, next) ->
            res.redirect 301, '//' + res.locals.page.url if req.header('host').match /(cdn.enactuslse|sifelse)/i
            next()

    _notFound: (req, res, next) ->
        res.locals.page.title = "Oops, we can't find what you are looking for! - #{res.locals.page.title}"
        res.status 404
        res.render '404',  layout: '_layouts/blank'

module.exports = (app) ->
    new Controller app
{'fraction_non_alphanumeric': 0.1386158886158886, 'fraction_numerical': 0.004914004914004914, 'mean_word_length': 1.9914268218003675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '4298591', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1452, 'n_words': 327}