-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.mjs
113 lines (101 loc) · 2.56 KB
/
next.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { request, gql } from 'graphql-request'
const ANALYTICS_BASE_URL = 'https://hn-ping2.hashnode.com';
const ADVANCED_ANALYTICS_BASE_URL = 'https://stats.hashnode.com';
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
const GQL_ENDPOINT = process.env.NEXT_PUBLIC_HASHNODE_GQL_ENDPOINT;
const host = process.env.NEXT_PUBLIC_HASHNODE_PUBLICATION_HOST;
const getBasePath = () => {
if (BASE_URL && BASE_URL.indexOf('/') !== -1) {
return BASE_URL.substring(BASE_URL.indexOf('/'));
}
return undefined;
};
const getRedirectionRules = async () => {
const query = gql`
query GetRedirectionRules {
publication(host: "${host}") {
id
redirectionRules {
source
destination
type
}
}
}
`;
const data = await request(GQL_ENDPOINT, query);
if (!data.publication) {
throw 'Please ensure you have set the env var NEXT_PUBLIC_HASHNODE_PUBLICATION_HOST correctly.';
}
const redirectionRules = data.publication.redirectionRules;
// convert to next.js redirects format
const redirects = redirectionRules
.filter((rule) => {
// Hashnode gives an option to set a wildcard redirect,
// but it doesn't work properly with Next.js
// the solution is to filter out all the rules with wildcard and use static redirects for now
return rule.source.indexOf('*') === -1;
})
.map((rule) => {
return {
source: rule.source,
destination: rule.destination,
permanent: rule.type === 'PERMANENT',
};
});
return redirects;
};
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
transpilePackages: ["chatbot", '@mdxeditor/editor'],
webpack(config) {
config.module.rules.push({
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ["@svgr/webpack"],
});
config.experiments = { ...config.experiments, topLevelAwait: true }
return config;
},
basePath: getBasePath(),
experimental: {
scrollRestoration: true,
},
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'cdn.hashnode.com',
},
{
protocol: 'https',
hostname: 'fast.wistia.com'
},
{
protocol: 'https',
hostname: 'mnmxcrqbhvdpcqvzmvxh.supabase.co'
}
],
},
async rewrites() {
return [
{
source: '/ping/data-event',
destination: `${ANALYTICS_BASE_URL}/api/data-event`,
},
{
source: '/ping/view',
destination: `${ANALYTICS_BASE_URL}/api/view`,
},
{
source: '/api/collect',
destination: `${ADVANCED_ANALYTICS_BASE_URL}/api/collect`,
},
];
},
async redirects() {
return await getRedirectionRules();
},
};
export default nextConfig;