Files
web/next.config.js
2024-04-26 14:06:31 +02:00

130 lines
4.1 KiB
JavaScript

import createJiti from "jiti"
import { login } from "./constants/routes/handleAuth.js"
import {
benefits,
myPages,
overview,
profile,
profileEdit,
} from "./constants/routes/myPages.js"
const jiti = createJiti(new URL(import.meta.url).pathname)
jiti("./env/server")
jiti("./env/client")
// We define SCANDIC_ENV_URL for stable environments on Netlify:
// production, stage and test. Avoid using SCANDIC_ENV_URL locally.
// For deployments to those branches we have SCANDIC_ENV_URL defined.
// Otherwise we fallback to DEPLOY_PRIME_URL from Netlify built-in variables.
// Locally we set DEPLOY_PRIME_URL
const ENV_URL = process.env.SCANDIC_ENV_URL || process.env.DEPLOY_PRIME_URL
// We set NEXTAUTH_URL here because next.config.js is included in Netlify
// functions when bundling. Otherwise we are unable to login on preview
// deployments. Netlify`s Next.js Runtime has built-in support for Next-Auth,
// but Next-Auth v5 is ESM and therefore not yet handle correctly by Netlify.
// This workaround should not be needed once Netlify fixes their code.
/** @type {import('next').NextConfig} */
const nextConfig = {
env: {
URL: ENV_URL,
NEXTAUTH_URL: `${ENV_URL}/api/web/auth`,
},
poweredByHeader: false,
eslint: { ignoreDuringBuilds: true },
images: {
remotePatterns: [
{
protocol: "https",
hostname: "eu-images.contentstack.com",
pathname: "/v3/assets/**",
},
{
protocol: "https",
hostname: "imagevault-stage.scandichotels.com",
},
{
protocol: "https",
hostname: "imagevault.scandichotels.com",
},
],
},
logging: {
fetches: {
fullUrl: true,
},
},
output: "standalone",
webpack: function (config, options) {
config.module.rules.push({
test: /\.(graphql|gql)/,
exclude: /node_modules/,
loader: "graphql-tag/loader",
})
return config
},
rewrites() {
return {
beforeFiles: [
{
source: benefits.da,
destination: "/da/my-pages/benefits",
},
{
source: benefits.de,
destination: "/de/my-pages/benefits",
},
{
source: benefits.fi,
destination: "/fi/my-pages/benefits",
},
{
source: benefits.no,
destination: "/no/my-pages/benefits",
},
{
source: benefits.sv,
destination: "/sv/my-pages/benefits",
},
{ source: login.da, destination: "/da/login" },
{ source: login.de, destination: "/de/login" },
{ source: login.fi, destination: "/fi/login" },
{ source: login.no, destination: "/no/login" },
{ source: login.sv, destination: "/sv/login" },
{ source: myPages.da, destination: "/da/my-pages/overview" },
{ source: myPages.de, destination: "/de/my-pages/overview" },
{ source: myPages.fi, destination: "/fi/my-pages/overview" },
{ source: myPages.no, destination: "/no/my-pages/overview" },
{ source: myPages.sv, destination: "/sv/my-pages/overview" },
{ source: overview.da, destination: "/da/my-pages/overview" },
{ source: overview.de, destination: "/de/my-pages/overview" },
{ source: overview.fi, destination: "/fi/my-pages/overview" },
{ source: overview.no, destination: "/no/my-pages/overview" },
{ source: overview.sv, destination: "/sv/my-pages/overview" },
{ source: profile.da, destination: "/da/my-pages/profile" },
{ source: profile.de, destination: "/de/my-pages/profile" },
{ source: profile.fi, destination: "/fi/my-pages/profile" },
{ source: profile.no, destination: "/no/my-pages/profile" },
{ source: profile.sv, destination: "/sv/my-pages/profile" },
{ source: profileEdit.da, destination: "/da/my-pages/profile/edit" },
{ source: profileEdit.de, destination: "/de/my-pages/profile/edit" },
{ source: profileEdit.fi, destination: "/fi/my-pages/profile/edit" },
{ source: profileEdit.no, destination: "/no/my-pages/profile/edit" },
{ source: profileEdit.sv, destination: "/sv/my-pages/profile/edit" },
],
}
},
}
export default nextConfig