@hx-midway/static-file
Version:
Midwayjs static-file alias 自动扫描,支持路径索引,允许 /path/index.html -> /path/
49 lines (48 loc) • 2.25 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StaticFileConfiguration = void 0;
const core_1 = require("@midwayjs/core");
const staticFile = require("@midwayjs/static-file");
const file_1 = require("./utils/file");
let StaticFileConfiguration = class StaticFileConfiguration {
async onConfigLoad() {
var _a, _b, _c;
const alias = {};
for (let conf in (_a = this === null || this === void 0 ? void 0 : this.config) === null || _a === void 0 ? void 0 : _a.dirs) {
const res2 = await (0, file_1.getIndexFiles)((_c = (_b = this === null || this === void 0 ? void 0 : this.config) === null || _b === void 0 ? void 0 : _b.dirs[conf]) === null || _c === void 0 ? void 0 : _c.dir, this.viewExt);
Object.assign(alias, res2);
}
return {
staticFile: { alias }
};
}
async onReady() {
// TODO something
}
};
__decorate([
(0, core_1.Config)('staticFile'),
__metadata("design:type", Object)
], StaticFileConfiguration.prototype, "config", void 0);
__decorate([
(0, core_1.Config)('view.defaultExtension'),
__metadata("design:type", Object)
], StaticFileConfiguration.prototype, "viewExt", void 0);
StaticFileConfiguration = __decorate([
(0, core_1.Configuration)({
namespace: 'hx:static:file',
imports: [
staticFile
]
})
], StaticFileConfiguration);
exports.StaticFileConfiguration = StaticFileConfiguration;
;