Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default [
{
files: ["**/*.js"],
rules: {
"@typescript-eslint/no-this-alias": "warn", // TODO(bkendall): remove allow to error.
"@typescript-eslint/no-unsafe-argument": "warn", // TODO(bkendall): remove allow to error.
"@typescript-eslint/no-unsafe-assignment": "warn", // TODO(bkendall): remove allow to error.
"@typescript-eslint/no-unsafe-call": "warn", // TODO(bkendall): remove allow to error.
Expand Down
14 changes: 5 additions & 9 deletions src/activator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

const middleware = require("./middleware");

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (24)

Require statement not part of import statement

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (24)

A `require()` style import is forbidden

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (22)

Require statement not part of import statement

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (22)

A `require()` style import is forbidden

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (26)

Require statement not part of import statement

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (26)

A `require()` style import is forbidden

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (22)

Require statement not part of import statement

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (22)

A `require()` style import is forbidden

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (24)

Require statement not part of import statement

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (24)

A `require()` style import is forbidden

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (26)

Require statement not part of import statement

Check warning on line 22 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (26)

A `require()` style import is forbidden
const promiseback = require("./utils/promiseback");

Check warning on line 23 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (24)

A `require()` style import is forbidden

Check warning on line 23 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (22)

A `require()` style import is forbidden

Check warning on line 23 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (26)

A `require()` style import is forbidden

Check warning on line 23 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (22)

A `require()` style import is forbidden

Check warning on line 23 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (24)

A `require()` style import is forbidden

Check warning on line 23 in src/activator.js

View workflow job for this annotation

GitHub Actions / test (26)

A `require()` style import is forbidden

const Activator = function (spec, provider) {
this.spec = spec;
Expand All @@ -37,8 +37,6 @@
};

Activator.prototype.buildStack = function () {
const self = this;

const stack = this.spec.stack.slice(0);
Object.entries(this.spec.before ?? {}).forEach(([name, wares]) => {
stack.splice(...[stack.indexOf(name), 0].concat(wares));
Expand All @@ -49,19 +47,17 @@
});

return stack.map((ware) => {
return typeof ware === "function" ? ware : middleware[ware](self.spec);
return typeof ware === "function" ? ware : middleware[ware](this.spec);
});
};

Activator.prototype.build = function () {
const self = this;

return function (req, res, next) {
promiseback(self.awaitConfig, 2)(req, res).then((config) => {
return (req, res, next) => {
promiseback(this.awaitConfig, 2)(req, res).then((config) => {
req.superstatic = config ?? {};

const stack = self.stack.slice(0).reverse();
const _run = function () {
const stack = this.stack.slice(0).reverse();
const _run = () => {
if (!stack.length) {
return next();
}
Expand Down
27 changes: 10 additions & 17 deletions src/responder.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ Responder.prototype.isNotModified = function (stats) {
};

Responder.prototype.handle = function (item, next) {
const self = this;
return this._handle(item)
.then((responded) => {
if (!responded && next) {
Expand All @@ -67,7 +66,7 @@ Responder.prototype.handle = function (item, next) {
return responded;
})
.catch((err) => {
return self.handleError(err);
return this.handleError(err);
});
};

Expand Down Expand Up @@ -104,34 +103,30 @@ Responder.prototype.handleError = function (err) {
};

Responder.prototype.handleStack = function (stack) {
const self = this;
if (stack.length) {
return this._handle(stack.shift()).then((responded) => {
return responded ? true : self.handleStack(stack);
return responded ? true : this.handleStack(stack);
});
}

return Promise.resolve(false);
};

Responder.prototype.handleFile = function (file) {
const self = this;
return this.provider(this.req, file.file).then((result) => {
if (!result) {
return false;
}

if (self.isNotModified(result)) {
return self.handleNotModified(result);
if (this.isNotModified(result)) {
return this.handleNotModified(result);
}

return self.handleFileStream(file, result);
return this.handleFileStream(file, result);
});
};

Responder.prototype.handleFileStream = function (file, result) {
const self = this;

this.streamedFile = file;
this.res.statusCode = file.status ?? 200;
if (this.res.statusCode === 200 && file.file === this.config.errorPage) {
Expand All @@ -156,10 +151,10 @@ Responder.prototype.handleFileStream = function (file, result) {

if (this.compressor) {
this.compressor(this.req, this.res, () => {
result.stream.pipe(self.res);
result.stream.pipe(this.res);
});
} else {
result.stream.pipe(self.res);
result.stream.pipe(this.res);
}

return awaitFinished(this.res).then(() => {
Expand All @@ -186,24 +181,22 @@ Responder.prototype.handleRedirect = function (redirect) {
};

Responder.prototype.handleMiddleware = function (middleware) {
const self = this;
return new Promise((resolve) => {
middleware(self.req, self.res, () => {
middleware(this.req, this.res, () => {
resolve(false);
});
});
};

Responder.prototype.handleRewrite = function (item) {
const self = this;
if (item.rewrite.destination) {
return self.handleFile({ file: item.rewrite.destination });
return this.handleFile({ file: item.rewrite.destination });
}

for (const key in this.rewriters) {
if (item.rewrite[key]) {
return this.rewriters[key](item.rewrite, this).then((result) => {
return self._handle(result);
return this._handle(result);
});
}
}
Expand Down
Loading