generated from Amery2010/nextjs-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 285
/
Copy pathnext.config.js
117 lines (112 loc) · 3.38 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/** @type {import('next').NextConfig} */
const { PHASE_PRODUCTION_BUILD, PHASE_EXPORT } = require('next/constants')
const mode = process.env.NEXT_PUBLIC_BUILD_MODE
const basePath = process.env.EXPORT_BASE_PATH || ''
const geminiApiKey = process.env.GEMINI_API_KEY || ''
const uploadProxyUrl = process.env.GEMINI_API_BASE_URL || 'https://generativelanguage.googleapis.com'
/** @type {(phase: string, defaultConfig: import("next").NextConfig) => Promise<import("next").NextConfig>} */
module.exports = async (phase) => {
const nextConfig = {
images: {
unoptimized: mode === 'export',
},
reactStrictMode: false,
}
if (mode === 'export') {
nextConfig.output = 'export'
// Only used for static deployment, the default deployment directory is the root directory
nextConfig.basePath = basePath
} else if (mode === 'standalone') {
nextConfig.output = 'standalone'
}
if (mode !== 'export') {
nextConfig.rewrites = async () => {
const beforeFilesConfig = geminiApiKey
? [
{
source: '/api/google/upload/v1beta/files',
has: [
{
type: 'query',
key: 'key',
value: '(?<key>.*)',
},
],
destination: `${uploadProxyUrl}/upload/v1beta/files?key=${geminiApiKey}`,
},
{
source: '/api/google/v1beta/files/:id',
has: [
{
type: 'query',
key: 'key',
value: '(?<key>.*)',
},
],
destination: `${uploadProxyUrl}/v1beta/files/:id?key=${geminiApiKey}`,
},
]
: [
{
source: '/api/google/upload/v1beta/files',
has: [
{
type: 'query',
key: 'key',
value: '(?<key>.*)',
},
],
destination: '/api/upload/files',
},
{
source: '/api/google/v1beta/files/:id',
has: [
{
type: 'query',
key: 'key',
value: '(?<key>.*)',
},
],
destination: '/api/upload/files?id=:id',
},
]
return {
beforeFiles: [
{
source: '/api/google/v1beta/models/:model',
destination: '/api/chat?model=:model',
},
{
source: '/api/google/upload/v1beta/files',
has: [
{
type: 'query',
key: 'uploadType',
value: 'resumable',
},
],
missing: [
{
type: 'query',
key: 'upload_id',
},
],
destination: `/api/upload`,
},
...beforeFilesConfig,
],
}
}
}
if (phase === PHASE_PRODUCTION_BUILD || phase === PHASE_EXPORT) {
const withSerwist = (await import('@serwist/next')).default({
// Note: This is only an example. If you use Pages Router,
// use something else that works, such as "service-worker/index.ts".
swSrc: 'app/sw.ts',
swDest: 'public/sw.js',
register: false,
})
return withSerwist(nextConfig)
}
return nextConfig
}