-
Notifications
You must be signed in to change notification settings - Fork 9
/
next.config.js
96 lines (83 loc) · 2.25 KB
/
next.config.js
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
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fetch = require("@zeit/fetch-retry")(require("node-fetch"));
module.exports = {
output: 'standalone',
typescript: {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
// your project has type errors.
// !! WARN !!
ignoreBuildErrors: true,
},
// Build redirect lists for player IDs and team IDs
redirects: async () => {
const players = await getPlayers();
const playerRedirects = players.map((player) => {
return {
source: `/players/${player.player_id}`,
destination: `/players/${player.url_slug}`,
permanent: false,
};
});
const teams = await getTeams();
const teamRedirects = teams.map((team) => {
return {
source: `/teams/${team.team_id}`,
destination: `/teams/${team.url_slug}`,
permanent: false,
};
});
return [
...(Array.isArray(playerRedirects) && playerRedirects.length > 0
? playerRedirects
: []),
...(Array.isArray(teamRedirects) && teamRedirects.length > 0
? teamRedirects
: []),
];
},
rewrites: async () => {
return [
{
source: "/sitemap.xml",
destination: "/api/sitemap",
},
];
},
webpack: (config, { dev, isServer, nextRuntime }) => {
if (!dev && isServer && nextRuntime === 'nodejs') {
const originalEntry = config.entry;
config.entry = async () => {
const entries = { ...(await originalEntry()) };
// These scripts can import components from the app and use ES modules
entries["./scripts/generate-index"] = "./scripts/generate-index";
return entries;
};
}
return config;
},
};
async function getPlayers() {
let players = [];
try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_DATABLASE_API}/players`
);
players = await response.json();
} catch (error) {
console.log(error);
}
return players;
}
async function getTeams() {
let teams = [];
try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_DATABLASE_API}/teams`
);
teams = await response.json();
} catch (error) {
console.log(error);
}
return teams;
}