2023-02-15 10:27:18 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2020-07-17 08:03:38 +00:00
|
|
|
require('dotenv').config();
|
2023-08-22 10:36:49 +00:00
|
|
|
const path = require('path');
|
2020-09-09 23:12:29 +00:00
|
|
|
const pkg = require('./package.json');
|
2020-07-17 08:03:38 +00:00
|
|
|
|
2024-05-13 06:15:49 +00:00
|
|
|
const basePath = process.env.BASE_PATH;
|
|
|
|
|
const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT;
|
|
|
|
|
const cloudMode = process.env.CLOUD_MODE;
|
|
|
|
|
const cloudUrl = process.env.CLOUD_URL;
|
|
|
|
|
const defaultLocale = process.env.DEFAULT_LOCALE;
|
|
|
|
|
const disableLogin = process.env.DISABLE_LOGIN;
|
|
|
|
|
const disableUI = process.env.DISABLE_UI;
|
|
|
|
|
const forceSSL = process.env.FORCE_SSL;
|
|
|
|
|
const frameAncestors = process.env.ALLOWED_FRAME_URLS;
|
|
|
|
|
const privateMode = process.env.PRIVATE_MODE;
|
|
|
|
|
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME;
|
2024-01-29 09:32:05 +00:00
|
|
|
|
2023-11-12 04:45:09 +00:00
|
|
|
const contentSecurityPolicy = [
|
|
|
|
|
`default-src 'self'`,
|
2024-07-29 02:51:14 +00:00
|
|
|
`img-src * data:`,
|
2023-11-12 04:45:09 +00:00
|
|
|
`script-src 'self' 'unsafe-eval' 'unsafe-inline'`,
|
|
|
|
|
`style-src 'self' 'unsafe-inline'`,
|
2023-12-20 17:31:33 +00:00
|
|
|
`connect-src 'self' api.umami.is cloud.umami.is`,
|
2024-01-29 09:32:05 +00:00
|
|
|
`frame-ancestors 'self' ${frameAncestors}`,
|
2023-11-12 04:45:09 +00:00
|
|
|
];
|
2022-08-01 06:29:47 +00:00
|
|
|
|
|
|
|
|
const headers = [
|
|
|
|
|
{
|
|
|
|
|
key: 'X-DNS-Prefetch-Control',
|
|
|
|
|
value: 'on',
|
|
|
|
|
},
|
2023-11-13 22:12:05 +00:00
|
|
|
{
|
2023-12-01 07:40:58 +00:00
|
|
|
key: 'Content-Security-Policy',
|
|
|
|
|
value: contentSecurityPolicy
|
|
|
|
|
.join(';')
|
|
|
|
|
.replace(/\s{2,}/g, ' ')
|
|
|
|
|
.trim(),
|
2022-08-01 06:29:47 +00:00
|
|
|
},
|
2023-11-13 22:12:05 +00:00
|
|
|
];
|
2022-08-01 06:29:47 +00:00
|
|
|
|
2024-01-29 09:32:05 +00:00
|
|
|
if (forceSSL) {
|
2022-08-01 06:29:47 +00:00
|
|
|
headers.push({
|
|
|
|
|
key: 'Strict-Transport-Security',
|
|
|
|
|
value: 'max-age=63072000; includeSubDomains; preload',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 00:37:43 +00:00
|
|
|
const rewrites = [];
|
|
|
|
|
|
2024-01-29 09:32:05 +00:00
|
|
|
if (collectApiEndpoint) {
|
2023-03-09 00:37:43 +00:00
|
|
|
rewrites.push({
|
2024-01-29 09:32:05 +00:00
|
|
|
source: collectApiEndpoint,
|
2023-03-09 00:48:44 +00:00
|
|
|
destination: '/api/send',
|
2023-03-09 00:37:43 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 09:32:05 +00:00
|
|
|
if (trackerScriptName) {
|
|
|
|
|
const names = trackerScriptName?.split(',').map(name => name.trim());
|
2023-04-19 15:49:16 +00:00
|
|
|
|
2023-04-20 08:12:43 +00:00
|
|
|
if (names) {
|
|
|
|
|
names.forEach(name => {
|
|
|
|
|
rewrites.push({
|
2023-04-20 08:52:49 +00:00
|
|
|
source: `/${name.replace(/^\/+/, '')}`,
|
2023-04-20 08:12:43 +00:00
|
|
|
destination: '/script.js',
|
|
|
|
|
});
|
2023-04-19 15:49:16 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-21 22:14:30 +00:00
|
|
|
const redirects = [
|
|
|
|
|
{
|
|
|
|
|
source: '/settings',
|
2024-02-15 06:13:13 +00:00
|
|
|
destination: '/settings/websites',
|
2024-01-29 09:32:05 +00:00
|
|
|
permanent: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
source: '/teams/:id',
|
2024-02-03 05:06:55 +00:00
|
|
|
destination: '/teams/:id/dashboard',
|
2023-04-21 22:14:30 +00:00
|
|
|
permanent: true,
|
|
|
|
|
},
|
2024-02-03 01:49:17 +00:00
|
|
|
{
|
|
|
|
|
source: '/teams/:id/settings',
|
2024-02-15 06:13:13 +00:00
|
|
|
destination: '/teams/:id/settings/team',
|
2024-02-03 01:49:17 +00:00
|
|
|
permanent: true,
|
|
|
|
|
},
|
2023-04-21 22:14:30 +00:00
|
|
|
];
|
2023-03-09 00:37:43 +00:00
|
|
|
|
2024-02-15 06:13:13 +00:00
|
|
|
if (cloudMode && cloudUrl) {
|
2023-03-09 00:37:43 +00:00
|
|
|
redirects.push({
|
2024-02-15 06:13:13 +00:00
|
|
|
source: '/settings/:path*',
|
|
|
|
|
destination: `${cloudUrl}/settings/:path*`,
|
2023-03-09 00:37:43 +00:00
|
|
|
permanent: false,
|
|
|
|
|
});
|
2024-02-15 06:13:13 +00:00
|
|
|
|
|
|
|
|
redirects.push({
|
|
|
|
|
source: '/teams/:id/settings/:path*',
|
|
|
|
|
destination: `${cloudUrl}/teams/:id/settings/:path*`,
|
|
|
|
|
permanent: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (disableLogin) {
|
|
|
|
|
redirects.push({
|
|
|
|
|
source: '/login',
|
|
|
|
|
destination: cloudUrl,
|
|
|
|
|
permanent: false,
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-03-09 00:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-29 12:29:22 +00:00
|
|
|
/** @type {import('next').NextConfig} */
|
2023-03-09 00:37:43 +00:00
|
|
|
const config = {
|
2023-09-30 02:18:44 +00:00
|
|
|
reactStrictMode: false,
|
2020-09-09 23:12:29 +00:00
|
|
|
env: {
|
2024-01-29 09:32:05 +00:00
|
|
|
basePath,
|
|
|
|
|
cloudMode,
|
|
|
|
|
cloudUrl,
|
2023-08-28 02:56:44 +00:00
|
|
|
configUrl: '/config',
|
2022-06-24 08:54:55 +00:00
|
|
|
currentVersion: pkg.version,
|
2024-01-29 09:32:05 +00:00
|
|
|
defaultLocale,
|
|
|
|
|
disableLogin,
|
|
|
|
|
disableUI,
|
2024-03-29 18:48:12 +00:00
|
|
|
privateMode,
|
2020-09-27 03:46:20 +00:00
|
|
|
},
|
2023-09-29 12:29:22 +00:00
|
|
|
basePath,
|
2022-07-07 16:24:32 +00:00
|
|
|
output: 'standalone',
|
2021-11-22 22:53:36 +00:00
|
|
|
eslint: {
|
|
|
|
|
ignoreDuringBuilds: true,
|
|
|
|
|
},
|
2022-12-13 03:45:38 +00:00
|
|
|
typescript: {
|
|
|
|
|
ignoreBuildErrors: true,
|
|
|
|
|
},
|
2020-07-17 08:03:38 +00:00
|
|
|
webpack(config) {
|
2023-09-29 12:29:22 +00: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 08:03:38 +00:00
|
|
|
|
2023-08-22 10:36:49 +00:00
|
|
|
config.resolve.alias['public'] = path.resolve('./public');
|
|
|
|
|
|
2020-07-17 08:03:38 +00:00
|
|
|
return config;
|
|
|
|
|
},
|
2020-10-05 07:45:24 +00:00
|
|
|
async headers() {
|
|
|
|
|
return [
|
2022-08-01 06:29:47 +00:00
|
|
|
{
|
|
|
|
|
source: '/:path*',
|
2023-11-13 22:12:05 +00:00
|
|
|
headers,
|
2023-11-12 04:45:09 +00:00
|
|
|
},
|
2022-08-02 07:24:17 +00:00
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
async rewrites() {
|
|
|
|
|
return [
|
2023-03-09 00:37:43 +00:00
|
|
|
...rewrites,
|
2020-10-05 07:45:24 +00:00
|
|
|
{
|
2022-08-02 07:24:17 +00:00
|
|
|
source: '/telemetry.js',
|
|
|
|
|
destination: '/api/scripts/telemetry',
|
2020-10-05 07:45:24 +00:00
|
|
|
},
|
2024-06-21 19:49:57 +00:00
|
|
|
{
|
2024-06-24 04:59:50 +00:00
|
|
|
source: '/teams/:teamId/:path((?!settings).*)*',
|
2024-05-27 06:04:18 +00:00
|
|
|
destination: '/:path*',
|
|
|
|
|
},
|
2020-12-04 06:28:05 +00:00
|
|
|
];
|
2020-10-05 07:45:24 +00:00
|
|
|
},
|
2023-03-09 00:37:43 +00:00
|
|
|
async redirects() {
|
|
|
|
|
return [...redirects];
|
|
|
|
|
},
|
2020-07-17 08:03:38 +00:00
|
|
|
};
|
2023-03-09 00:37:43 +00:00
|
|
|
|
|
|
|
|
module.exports = config;
|