forked from 77media/video-flow
接口改成process.env.NEXT_PUBLIC_BASE_URL
This commit is contained in:
parent
6427d074b2
commit
2d363b384d
@ -10,7 +10,14 @@
|
||||
*/
|
||||
const localPost = async <T>(url: string, data: any): Promise<T> => {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
// 使用环境变量中的 BASE_URL(生产要求使用 NEXT_PUBLIC_BASE_URL)
|
||||
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || '';
|
||||
const isAbsolute = /^https?:\/\//i.test(url);
|
||||
const normalizedBase = baseUrl.replace(/\/$/, '');
|
||||
const normalizedPath = url.startsWith('/') ? url : `/${url}`;
|
||||
const fullUrl = isAbsolute ? url : `${normalizedBase}${normalizedPath}`;
|
||||
|
||||
const response = await fetch(fullUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user