This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.mjs
114 lines (106 loc) · 3.09 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
114
import fs from 'node:fs/promises';
import path from 'node:path';
/**
* @template {import('next').NextConfig} T
* @param {T} config - A generic parameter that flows through to the return type
* @constraint {{import('next').NextConfig}}
*/
function defineNextConfig(config) {
return config;
}
const getCorsHeaders = () => {
const headers = {};
headers['Access-Control-Allow-Origin'] = '*';
headers['Access-Control-Allow-Credentials'] = 'true';
headers['Access-Control-Allow-Methods'] = 'GET,OPTIONS,PATCH,DELETE,POST,PUT';
headers['Access-Control-Allow-Headers'] =
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Authorization';
return Object.entries(headers).map(([key, value]) => ({ key, value }));
};
export default defineNextConfig({
experimental: {
serverComponentsExternalPackages: [
'pdf-parse',
// 'sharp', // Used for transformer.js
// 'onnxruntime-node', // Used for transformer.js
// 'webworker-threads', //used for Natural
],
},
webpack: (config) => {
// See https://webpack.js.org/configuration/resolve/#resolvealias
config.resolve.alias = {
...config.resolve.alias,
sharp$: false,
'onnxruntime-node$': false,
'mongodb-client-encryption': false, // Unused for Natural
aws4: false, // Unused for Natural
'webworker-threads': false, // Unused for Natural
};
return config;
},
reactStrictMode: true,
swcMinify: true,
publicRuntimeConfig: {},
headers: async () => {
return [
{
source: '/api/(.*)',
headers: getCorsHeaders(),
},
];
},
rewrites: async () => {
return [
// FastAPI routes
{
source: '/api/hyperion/:path*',
destination:
process.env.NODE_ENV === 'development'
? 'http://127.0.0.1:8000/api/hyperion/:path*'
: '/api/hyperion/:path*',
},
{
source: '/docs',
destination:
process.env.NODE_ENV === 'development'
? 'http://127.0.0.1:8000/docs'
: '/api/hyperion/docs',
},
{
source: '/openapi.json',
destination:
process.env.NODE_ENV === 'development'
? 'http://127.0.0.1:8000/openapi.json'
: '/api/hyperion/openapi.json',
},
{
source: '/api/:path*',
destination: '/api/:path*',
},
];
},
});
async function copyFiles() {
try {
await fs.access('public/');
} catch {
await fs.mkdir('public/', { recursive: true });
}
const wasmFiles = (
await fs.readdir('node_modules/onnxruntime-web/dist/')
).filter((file) => path.extname(file) === '.wasm');
await Promise.all([
fs.copyFile(
'node_modules/@ricky0123/vad-web/dist/vad.worklet.bundle.min.js',
'public/vad.worklet.bundle.min.js'
),
fs.copyFile(
'node_modules/@ricky0123/vad-web/dist/silero_vad.onnx',
'public/silero_vad.onnx'
),
...wasmFiles.map((file) =>
fs.copyFile(`node_modules/onnxruntime-web/dist/${file}`, `public/${file}`)
),
]);
}
copyFiles();