umami/next.config.js

147 lines
3.1 KiB
JavaScript
Raw Normal View History

2023-02-15 11:27:18 +01:00
/* eslint-disable @typescript-eslint/no-var-requires */
2020-07-17 10:03:38 +02:00
require('dotenv').config();
2023-08-22 12:36:49 +02:00
const path = require('path');
const pkg = require('./package.json');
2020-07-17 10:03:38 +02:00
2022-08-01 08:29:47 +02:00
const contentSecurityPolicy = `
default-src 'self';
img-src *;
2023-09-29 14:29:22 +02:00
script-src 'self' 'unsafe-eval' 'unsafe-inline';
2022-08-01 08:29:47 +02:00
style-src 'self' 'unsafe-inline';
connect-src 'self' api.umami.is;
frame-ancestors 'self' ${process.env.ALLOWED_FRAME_URLS};
2022-08-01 08:29:47 +02:00
`;
const headers = [
{
key: 'X-DNS-Prefetch-Control',
value: 'on',
},
{
key: 'X-Frame-Options',
value: 'SAMEORIGIN',
},
{
key: 'Content-Security-Policy',
value: contentSecurityPolicy.replace(/\s{2,}/g, ' ').trim(),
},
];
if (process.env.FORCE_SSL) {
headers.push({
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload',
});
}
const rewrites = [];
if (process.env.COLLECT_API_ENDPOINT) {
rewrites.push({
2023-03-09 01:48:44 +01:00
source: process.env.COLLECT_API_ENDPOINT,
destination: '/api/send',
});
}
2023-04-19 17:49:16 +02:00
if (process.env.TRACKER_SCRIPT_NAME) {
2023-04-20 10:12:43 +02:00
const names = process.env.TRACKER_SCRIPT_NAME?.split(',').map(name => name.trim());
2023-04-19 17:49:16 +02:00
2023-04-20 10:12:43 +02:00
if (names) {
names.forEach(name => {
rewrites.push({
2023-04-20 10:52:49 +02:00
source: `/${name.replace(/^\/+/, '')}`,
2023-04-20 10:12:43 +02:00
destination: '/script.js',
});
2023-04-19 17:49:16 +02:00
});
}
}
2023-04-22 00:14:30 +02:00
const redirects = [
{
source: '/settings',
2023-08-27 23:15:02 +02:00
destination: process.env.CLOUD_MODE
2023-10-14 19:35:57 +02:00
? `${process.env.CLOUD_URL}/settings/websites`
2023-08-27 23:15:02 +02:00
: '/settings/websites',
2023-04-22 00:14:30 +02:00
permanent: true,
},
];
if (process.env.CLOUD_MODE && process.env.CLOUD_URL && process.env.DISABLE_LOGIN) {
redirects.push({
source: '/login',
2023-04-25 23:48:50 +02:00
destination: process.env.CLOUD_URL,
permanent: false,
});
}
2023-09-29 14:29:22 +02:00
const basePath = process.env.BASE_PATH;
/** @type {import('next').NextConfig} */
const config = {
2023-09-30 04:18:44 +02:00
reactStrictMode: false,
env: {
2023-09-29 14:29:22 +02:00
basePath: basePath || '',
cloudMode: !!process.env.CLOUD_MODE,
2023-08-28 04:56:44 +02:00
cloudUrl: process.env.CLOUD_URL,
configUrl: '/config',
2022-06-24 10:54:55 +02:00
currentVersion: pkg.version,
defaultLocale: process.env.DEFAULT_LOCALE,
2023-09-30 04:18:44 +02:00
disableLogin: process.env.DISABLE_LOGIN,
disableUI: process.env.DISABLE_UI,
isProduction: process.env.NODE_ENV === 'production',
2020-09-27 05:46:20 +02:00
},
2023-09-29 14:29:22 +02:00
basePath,
2022-07-07 18:24:32 +02:00
output: 'standalone',
2021-11-22 23:53:36 +01:00
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
2020-07-17 10:03:38 +02:00
webpack(config) {
2023-09-29 14:29:22 +02:00
const fileLoaderRule = config.module.rules.find(rule => rule.test?.test?.('.svg'));
config.module.rules.push(
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/,
},
{
test: /\.svg$/i,
issuer: fileLoaderRule.issuer,
resourceQuery: { not: [...fileLoaderRule.resourceQuery.not, /url/] },
use: ['@svgr/webpack'],
},
);
fileLoaderRule.exclude = /\.svg$/i;
2020-07-17 10:03:38 +02:00
2023-08-22 12:36:49 +02:00
config.resolve.alias['public'] = path.resolve('./public');
2020-07-17 10:03:38 +02:00
return config;
},
async headers() {
return [
2022-08-01 08:29:47 +02:00
{
source: '/:path*',
headers,
},
2022-08-02 09:24:17 +02:00
];
},
async rewrites() {
return [
...rewrites,
{
2022-08-02 09:24:17 +02:00
source: '/telemetry.js',
destination: '/api/scripts/telemetry',
},
2020-12-04 07:28:05 +01:00
];
},
async redirects() {
return [...redirects];
},
2020-07-17 10:03:38 +02:00
};
module.exports = config;