Skip to content

fix: explicitly type image config in ipx edge function #1457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2022
Merged
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
7 changes: 6 additions & 1 deletion plugin/src/templates/edge/ipx.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Accepts } from "https://deno.land/x/[email protected]/mod.ts";
import type { Context } from "netlify:edge";
// Available at build time
import imageconfig from "../functions-internal/_ipx/imageconfig.json" assert {
type: "json",
};

const defaultFormat = "webp"

interface ImageConfig extends Record<string, unknown> {
formats?: string[];
}

/**
* Implement content negotiation for images
*/
Expand All @@ -14,7 +19,7 @@ const defaultFormat = "webp"
const handler = async (req: Request, context: Context) => {
const { searchParams } = new URL(req.url);
const accept = new Accepts(req.headers);
const { formats = [defaultFormat] } = imageconfig;
const { formats = [defaultFormat] } = imageconfig as ImageConfig;
if (formats.length === 0) {
formats.push(defaultFormat);
}
Expand Down