@midwayjs/static-file
Version:
midway static file component
54 lines • 2.3 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 static_middleware_1 = require("./middleware/static.middleware");
const DefaultConfig = require("./config/config.default");
let StaticFileConfiguration = class StaticFileConfiguration {
async onConfigLoad() {
if (this.applicationManager.getApplication('faas')) {
return {
staticFile: {
buffer: true,
},
};
}
}
async onReady(container) {
this.applicationManager
.getApplications(['koa', 'faas', 'egg'])
.forEach(app => {
if (container.hasNamespace('cross-domain')) {
app.getMiddleware().insertAfter(static_middleware_1.StaticMiddleware, 'cors');
}
else {
app.getMiddleware().insertFirst(static_middleware_1.StaticMiddleware);
}
});
}
};
__decorate([
(0, core_1.Inject)(),
__metadata("design:type", core_1.MidwayApplicationManager)
], StaticFileConfiguration.prototype, "applicationManager", void 0);
StaticFileConfiguration = __decorate([
(0, core_1.Configuration)({
namespace: 'static-file',
importConfigs: [
{
default: DefaultConfig,
},
],
})
], StaticFileConfiguration);
exports.StaticFileConfiguration = StaticFileConfiguration;
//# sourceMappingURL=configuration.js.map