fix: add automatic deployment skew protection
This commit is contained in:
1 parent
0dc16e832d
commit
d173dd3194
2 files changed
+31
No files matched your search
@@ -1,8 +1,23 @@
|
|||||||
|
import { execFileSync } from "node:child_process";
|
||||||
import withBundleAnalyzer from "@next/bundle-analyzer";
|
import withBundleAnalyzer from "@next/bundle-analyzer";
|
||||||
import { withSentryConfig } from "@sentry/nextjs";
|
import { withSentryConfig } from "@sentry/nextjs";
|
||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
import createNextIntlPlugin from "next-intl/plugin";
|
import createNextIntlPlugin from "next-intl/plugin";
|
||||||
|
|
||||||
|
function resolveDeploymentId(): string | undefined {
|
||||||
|
const configuredId = process.env.NEXT_DEPLOYMENT_ID?.trim();
|
||||||
|
if (configuredId) return configuredId;
|
||||||
|
|
||||||
|
try {
|
||||||
|
return execFileSync("git", ["rev-parse", "HEAD"], {
|
||||||
|
encoding: "utf8",
|
||||||
|
stdio: ["ignore", "pipe", "ignore"],
|
||||||
|
}).trim();
|
||||||
|
} catch {
|
||||||
|
return process.env.APP_VERSION?.trim() || undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const securityHeaders = [
|
const securityHeaders = [
|
||||||
{ key: "X-DNS-Prefetch-Control", value: "on" },
|
{ key: "X-DNS-Prefetch-Control", value: "on" },
|
||||||
{
|
{
|
||||||
@@ -20,6 +35,7 @@ const securityHeaders = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
|
deploymentId: resolveDeploymentId(),
|
||||||
turbopack: {},
|
turbopack: {},
|
||||||
serverExternalPackages: ["mariadb", "lzma", "sharp", "pino", "pino-pretty"],
|
serverExternalPackages: ["mariadb", "lzma", "sharp", "pino", "pino-pretty"],
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { execFileSync } from "node:child_process";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import nextConfig from "../../next.config";
|
||||||
|
|
||||||
|
describe("deployment version skew protection", () => {
|
||||||
|
it("uses an explicit deployment ID or the current Git commit", () => {
|
||||||
|
const gitCommit = execFileSync("git", ["rev-parse", "HEAD"], {
|
||||||
|
encoding: "utf8",
|
||||||
|
}).trim();
|
||||||
|
|
||||||
|
expect(nextConfig.deploymentId).toBe(
|
||||||
|
process.env.NEXT_DEPLOYMENT_ID?.trim() || gitCommit,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user