Skip to content

Open-source status page, incident response and uptime monitoring

3.0 KB
Raw Blame
import { withSentryConfig } from "@sentry/nextjs";
import type { NextConfig } from "next";
import createNextIntlPlugin from "next-intl/plugin";

import { defaultLocale, locales } from "./src/i18n/config";

const isDev = process.env.NODE_ENV === "development";

const cspHeader = `
    default-src 'self';
    script-src 'self' 'unsafe-inline'${isDev ? " 'unsafe-eval'" : ""};
    style-src 'self' 'unsafe-inline';
    img-src *;
    font-src 'self';
    object-src 'none';
    base-uri 'self';
    form-action 'self';
    frame-ancestors *;
    connect-src 'self' https://*.ingest.us.sentry.io;
    worker-src 'self' blob:;
    upgrade-insecure-requests;
    `;

const withNextIntl = createNextIntlPlugin({
  requestConfig: "./src/i18n/request.ts",
  experimental: {
    srcPath: "./src",
    extract: {
      sourceLocale: defaultLocale,
    },
    messages: {
      path: "./messages",
      format: "json",
      locales,
    },
  },
});

// ICON_SET=nucleo swaps the icon set at resolution time (see packages/icons)
const useNucleoIcons = process.env.ICON_SET === "nucleo";

const nextConfig: NextConfig = {
  output: process.env.SELF_HOST === "true" ? "standalone" : undefined,
  experimental: {
    authInterrupts: true,
    // barrel-optimize only when unaliased — the rewrite would bypass the nucleo alias
    optimizePackageImports: useNucleoIcons ? [] : ["@openstatus/icons"],
  },
  turbopack: useNucleoIcons
    ? { resolveAlias: { "@openstatus/icons": "@openstatus/icons/nucleo" } }
    : undefined,
  webpack: (config) => {
    if (useNucleoIcons) {
      config.resolve.alias["@openstatus/icons$"] = "@openstatus/icons/nucleo";
    }
    return config;
  },
  images: {
    remotePatterns: [
      new URL("https://openstatus.dev/**"),
      new URL("https://**.public.blob.vercel-storage.com/**"),
    ],
  },
  logging: {
    fetches: {
      fullUrl: true,
    },
  },
  async headers() {
    return [
      {
        source: "/(.*)",
        headers: [
          {
            key: "Content-Security-Policy",
            value: cspHeader.replace(/\n/g, ""),
          },
        ],
      },
    ];
  },
};

// For detailed options, refer to the official documentation:
// - Webpack plugin options: https://github.com/getsentry/sentry-webpack-plugin#options
// - Next.js Sentry setup guide: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
const sentryConfig = {
  // Prevent log output unless running in a CI environment (helps reduce noise in logs)
  silent: !process.env.CI,
  org: "openstatus",
  project: "openstatus",
  authToken: process.env.SENTRY_AUTH_TOKEN,

  // Upload a larger set of source maps for improved stack trace accuracy (increases build time)
  widenClientFileUpload: true,

  // If set to true, transpiles Sentry SDK to be compatible with IE11 (increases bundle size)
  transpileClientSDK: false,

  // Tree-shake Sentry logger statements to reduce bundle size
  webpack: {
    treeshake: {
      removeDebugLogging: true,
    },
  },
};

export default withSentryConfig(withNextIntl(nextConfig), sentryConfig);