youzanyun-devtool-worker
Version:
- web - ws - proxy
34 lines (33 loc) • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const spring4js_nodejs_1 = require("spring4js-nodejs");
const mime_1 = tslib_1.__importDefault(require("mime"));
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
let ActionLocalFileService = class ActionLocalFileService {
async processRequest(ctx, next) {
let { js, proPath, file } = ctx.query;
let fileLocalPath;
if (js === "mock") {
fileLocalPath = proPath ? path_1.default.resolve(proPath, `dist/${file}`) : file;
}
else if (ctx.path === '/_yzydev_/local/file') {
const { filePath } = ctx.query;
fileLocalPath = filePath;
}
else {
return false;
}
const contentType = mime_1.default.getType(fileLocalPath);
ctx.set({
"Content-Type": contentType + ";charset=utf-8"
});
ctx.body = fs_extra_1.default.createReadStream(fileLocalPath);
return true;
}
};
ActionLocalFileService = tslib_1.__decorate([
spring4js_nodejs_1.Service()
], ActionLocalFileService);
exports.default = ActionLocalFileService;