Skip to content

Commit

Permalink
apply new prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bkendall committed Jan 2, 2024
1 parent ee8231c commit 6893457
Show file tree
Hide file tree
Showing 25 changed files with 113 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ cli
app.listen(() => resolve());
console.log(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`Superstatic started.\nVisit http://${options.hostname}:${options.port} to view your app.`
`Superstatic started.\nVisit http://${options.hostname}:${options.port} to view your app.`,
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function env(spec: { env: Record<string, string> }) {
return (
req: Request & SuperstaticRequest,
res: Response & SuperstaticResponse,
next: () => void
next: () => void,
): void => {
// const config = req.superstatic.env;
let env = undefined;
Expand Down
22 changes: 11 additions & 11 deletions src/middleware/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = function () {

// We want to check for some other files, namely an `index.html` if this were a directory.
const pathAsDirectoryWithIndex = pathutils.asDirectoryIndex(
pathutils.addTrailingSlash(pathname)
pathutils.addTrailingSlash(pathname),
);
return providerResult(req, res, pathAsDirectoryWithIndex).then(
(pathAsDirectoryWithIndexResult) => {
Expand All @@ -94,7 +94,7 @@ module.exports = function () {
// No infinite redirects
return res.superstatic.handle({
redirect: normalizeRedirectPath(
pathutils.removeTrailingSlash(pathname) + search
pathutils.removeTrailingSlash(pathname) + search,
),
});
}
Expand All @@ -106,7 +106,7 @@ module.exports = function () {
// If we haven't returned yet, our path is "correct" and we should be serving a file, not redirecting.
return res.superstatic.handleFileStream(
{ file: pathAsDirectoryWithIndex },
pathAsDirectoryWithIndexResult
pathAsDirectoryWithIndexResult,
);
}

Expand Down Expand Up @@ -134,19 +134,19 @@ module.exports = function () {
// (This works because we are in the cleanURL block.)
return res.superstatic.handle({
redirect: normalizeRedirectPath(
pathutils.removeTrailingSlash(pathname) + search
pathutils.removeTrailingSlash(pathname) + search,
),
});
}
if (trailingSlashBehavior === true && !hasTrailingSlash) {
// If we are missing a slash and need to add it, we want to make sure our appended path is cleaned up.
appendedPath = pathutils.removeTrailingString(
appendedPath,
".html"
".html",
);
appendedPath = pathutils.removeTrailingString(
appendedPath,
"/index"
"/index",
);
return res.superstatic.handle({
redirect:
Expand All @@ -159,25 +159,25 @@ module.exports = function () {
redirect: normalizeRedirectPath(
pathutils.removeTrailingString(
appendedPath,
"/index.html"
) + search
"/index.html",
) + search,
),
});
}
// And if we should be serving a file and we're at the right path, we'll serve the file.
return res.superstatic.handleFileStream(
{ file: appendedPath },
appendedPathResult
appendedPathResult,
);
}

return next();
}
},
);
}

return next();
}
},
);
})
.catch((err) => {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = function (spec) {
handles.push({ data: defaultErrorContent, status: 404 });
}
res.superstatic.handle(handles, next);
}
},
);
};
};
2 changes: 1 addition & 1 deletion src/middleware/protect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function (spec) {
if (spec.protect || config.protect) {
return basicAuth.apply(
basicAuth,
(spec.protect || config.protect).split(":")
(spec.protect || config.protect).split(":"),
)(req, res, next);
}

Expand Down
2 changes: 1 addition & 1 deletion src/middleware/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module.exports = function () {
config.forEach((redir) => {
const glob = redir.glob || redir.source;
redirects.push(
new Redirect(glob, redir.regex, redir.destination, redir.type)
new Redirect(glob, redir.regex, redir.destination, redir.type),
);
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/rewrites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = function () {
return function (
req: IncomingMessage & { superstatic: Configuration },
res: ServerResponse & { superstatic: Responder },
next: NextFunction
next: NextFunction,
) {
const rewrites = matcher(req.superstatic.rewrites || []);
const pathname: string = urlParser.parse(req.url).pathname;
Expand Down
6 changes: 3 additions & 3 deletions src/providers/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as fs from "node:fs";
const pathjoin = require("join-path"); // eslint-disable-line @typescript-eslint/no-var-requires

async function multiStat(
paths: string[]
paths: string[],
): Promise<fs.Stats & { pathname: string }> {
// const pathname = paths.shift();
let err: any;
Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports = function provider(options: any) {

return async function (
req: unknown,
pathname: string
pathname: string,
): Promise<{
modified: number;
size: number;
Expand All @@ -101,7 +101,7 @@ module.exports = function provider(options: any) {

const fullPathnames: string[] = publicPaths.map((p) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
pathjoin(cwd, p, pathname)
pathjoin(cwd, p, pathname),
);

try {
Expand Down
14 changes: 8 additions & 6 deletions src/responder.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ Responder.prototype._handle = function (item) {
}

return Promise.reject(
new Error(JSON.stringify(item) + " is not a recognized responder directive")
new Error(
JSON.stringify(item) + " is not a recognized responder directive",
),
);
};

Expand Down Expand Up @@ -137,7 +139,7 @@ Responder.prototype.handleFileStream = function (file, result) {
}
this.res.setHeader(
"Content-Type",
result.contentType || mime.contentType(path.extname(file.file))
result.contentType || mime.contentType(path.extname(file.file)),
);
if (result.size) {
this.res.setHeader("Content-Length", result.size);
Expand All @@ -148,7 +150,7 @@ Responder.prototype.handleFileStream = function (file, result) {
if (result.modified) {
this.res.setHeader(
"Last-Modified",
new Date(result.modified).toUTCString()
new Date(result.modified).toUTCString(),
);
}

Expand Down Expand Up @@ -207,16 +209,16 @@ Responder.prototype.handleRewrite = function (item) {
}
return Promise.reject(
new Error(
"Unable to find a matching rewriter for " + JSON.stringify(item.rewrite)
)
"Unable to find a matching rewriter for " + JSON.stringify(item.rewrite),
),
);
};

Responder.prototype.handleData = function (data) {
this.res.statusCode = data.status || 200;
this.res.setHeader(
"Content-Type",
data.contentType || "text/html; charset=utf-8"
data.contentType || "text/html; charset=utf-8",
);
this.res.end(data.data);
return Promise.resolve(true);
Expand Down
4 changes: 2 additions & 2 deletions src/superstatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const superstatic = function (spec = {}) {
{
cwd: cwd, // default current working directory
},
config
)
config,
),
);

// Select compression middleware
Expand Down
4 changes: 2 additions & 2 deletions src/utils/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function join(...arr: string[]): string {
function getCountryCode(headers: Record<string, string>): string {
const overrideValue = cookieValue(
headers.cookie,
"firebase-country-override"
"firebase-country-override",
);
if (overrideValue) {
return overrideValue;
Expand All @@ -86,7 +86,7 @@ function getCountryCode(headers: Record<string, string>): string {
function getI18nLanguages(headers: Record<string, string>): string[] {
const overrideValue = cookieValue(
headers.cookie,
"firebase-language-override"
"firebase-language-override",
);
if (overrideValue) {
return overrideValue.includes(",")
Expand Down
6 changes: 3 additions & 3 deletions test/unit/loaders/config-file.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("loading config files", () => {
superstatic: {
key: "value",
},
})
}),
);
});

Expand Down Expand Up @@ -82,7 +82,7 @@ describe("loading config files", () => {
await fs.writeFile(
"superstatic.json",
'{"firebase": "superstatic", "public": "./"}',
"utf-8"
"utf-8",
);

const config = loadConfigFile({
Expand All @@ -103,7 +103,7 @@ describe("loading config files", () => {
await fs.writeFile(
"firebase.json",
'{"firebase": "example", "public": "./"}',
"utf-8"
"utf-8",
);

const config = loadConfigFile({
Expand Down
4 changes: 2 additions & 2 deletions test/unit/middleware/env.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("env", () => {
env: {
key: "value",
},
})
}),
);

request(app)
Expand All @@ -63,7 +63,7 @@ describe("env", () => {
env: {
key: "value",
},
})
}),
);

request(app)
Expand Down
10 changes: 5 additions & 5 deletions test/unit/middleware/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("i18n", () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
res.superstatic = new Responder(req, res, { provider });
next();
}
},
);
});

Expand Down Expand Up @@ -140,7 +140,7 @@ describe("i18n", () => {
.set("accept-language", "en")
.set(
"cookie",
"firebase-language-override=fr; firebase-country-override=ca"
"firebase-language-override=fr; firebase-country-override=ca",
)
.expect(200, "French CA!");
});
Expand Down Expand Up @@ -173,7 +173,7 @@ describe("static server with trailing slash customization", () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
res.superstatic = new Responder(req, res, { provider });
next();
}
},
);
});

Expand Down Expand Up @@ -423,8 +423,8 @@ describe("static server with trailing slash customization", () => {
app.use(
files(
{ trailingSlash: t.trailingSlashBehavior, cleanUrls: t.cleanUrls },
{ provider: provider }
)
{ provider: provider },
),
);

const r = request(app).get(tt.path);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/middleware/headers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("cors middleware", () => {
headers: [{ key: "custom-header", value: "for testing" }],
},
],
})
}),
)
.use(okay);

Expand All @@ -111,7 +111,7 @@ describe("cors middleware", () => {
headers: [{ key: "custom-header", value: "for testing" }],
},
],
})
}),
)
.use(okay);

Expand Down
16 changes: 8 additions & 8 deletions test/unit/middleware/missing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ describe("custom not found", () => {
(
req: connect.IncomingMessage,
res: any, // TODO(bkendall): extend http.ServerResponse.
next: connect.NextFunction
next: connect.NextFunction,
): void => {
res.superstatic = new Responder(req, res, { provider: provider });
next();
}
},
);
});

Expand All @@ -68,7 +68,7 @@ describe("custom not found", () => {
it("skips middleware on file serve error", async () => {
app
.use(
missing({ errorPage: "/does-not-exist.html" }, { provider: provider })
missing({ errorPage: "/does-not-exist.html" }, { provider: provider }),
)
.use((req, res) => {
res.end("does not exist");
Expand All @@ -82,16 +82,16 @@ describe("custom not found", () => {
await fs.mkdir(".tmp/i18n/fr", { recursive: true });
await fs.writeFile(
".tmp/i18n/fr/not-found.html",
"my custom 404, in French"
"my custom 404, in French",
);
});

it("should resolve to the normal error page by default", async () => {
app.use(
missing(
{ errorPage: "/not-found.html", i18n: { root: "/i18n" } },
{ provider: provider }
)
{ provider: provider },
),
);

await request(app).get("/anything").expect(404, "custom not found file");
Expand All @@ -101,8 +101,8 @@ describe("custom not found", () => {
app.use(
missing(
{ errorPage: "/not-found.html", i18n: { root: "/i18n" } },
{ provider: provider }
)
{ provider: provider },
),
);

await request(app)
Expand Down
Loading

0 comments on commit 6893457

Please sign in to comment.