'use strict';

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var Router = require('koa-router');
var http = require('http');
var MemoryFile = require('../components/MemoryFile');
var httpRouter = Router();
httpRouter.get('/source/*', _regenerator2.default.mark(function _callee(next) {
    var path, query, file;
    return _regenerator2.default.wrap(function _callee$(_context) {
        while (1) {
            switch (_context.prev = _context.next) {
                case 0:
                    path = this.params[0];
                    query = this.request.url.split('?');

                    query = query[1] ? '?' + query[1] : '';
                    file = MemoryFile.get(path + query);

                    if (file) {
                        this.response.status = 200;
                        this.response.contentType = 'text/javascript';
                        this.response.body = file.getContent();
                    } else {
                        this.response.status = 404;
                    }

                case 5:
                case 'end':
                    return _context.stop();
            }
        }
    }, _callee, this);
}));
module.exports = httpRouter;