deepdetection / frontend /next.config.js
akagtag's picture
feat: update frontend to proxy requests to Hugging Face Space API and configure environment variables
0604cf4
const path = require('path')
function trimTrailingSlash(value) {
return value.replace(/\/+$/, '')
}
function resolveApiBaseUrl() {
const explicitApiUrl = process.env.NEXT_PUBLIC_API_URL?.trim()
if (explicitApiUrl) {
return trimTrailingSlash(explicitApiUrl)
}
const hfSpaceId = (process.env.NEXT_PUBLIC_HF_SPACE_ID ?? 'akagtag/deepdetection').trim()
const [owner, space] = hfSpaceId.split('/')
if (owner && space) {
return `https://${owner}-${space}.hf.space`
}
return 'http://localhost:8000'
}
const API_BASE_URL = resolveApiBaseUrl()
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
outputFileTracingRoot: path.join(__dirname),
async rewrites() {
return [
{
source: '/api/:path*',
destination: `${API_BASE_URL}/:path*`,
},
]
},
}
module.exports = nextConfig