source-map.js 636 Bytes
import config from '../../../config/config';
import fs from 'fs';
import path from 'path';
import Router from 'koa-router';

let r = new Router();


r.get('/load', (ctx, next) => {
    const reqPath = ctx.request.query.path;
    const filePath = path.join(config.sourceMapDir, reqPath);

    if (fs.existsSync(filePath)) {
        const rs = fs.createReadStream(filePath, {
            encoding: 'utf-8'
        });

        const fileName = path.basename(filePath)

        ctx.set('Content-Type', 'application/javascript; charset=utf-8');
        ctx.response.body = rs;
        return;
    }
    return next();
});

export default r;