in src/middleware/env.ts [33:62]
export function env(spec: { env: { [key: string]: string } }) {
return (
req: Request & SuperstaticRequest,
res: Response & SuperstaticResponse,
next: () => void
): void => {
// const config = req.superstatic.env;
let env;
if (spec.env || req.superstatic.env) {
env = Object.assign({}, req.superstatic.env, spec.env);
} else {
return next();
}
if (req.url === "/__/env.json") {
res.superstatic.handleData({
data: JSON.stringify(env, null, 2),
contentType: mime.contentType("json") || ""
});
} else if (req.url === "/__/env.js") {
const payload = template.replace("{{ENV}}", JSON.stringify(env));
res.superstatic.handleData({
data: payload,
contentType: mime.contentType("js") || ""
});
}
return next();
};
}