feat: 新增可配置的路径前缀以支持子路径部署
添加前后端环境变量配置示例,新增后端路径前缀配置项,更新后端路由与静态文件挂载逻辑,调整前端代理配置与 API 调用代码,适配子路径部署场景。
This commit is contained in:
@@ -225,6 +225,7 @@ textarea{width:100%;padding:10px;border:1px solid #ddd;border-radius:8px;font-si
|
||||
|
||||
<script>
|
||||
const API = '';
|
||||
const API_PREFIX = window.location.pathname.startsWith('/app_03') ? '/app_03/api' : '/api';
|
||||
let TOKEN = '';
|
||||
let currentReportId = '';
|
||||
let ocrDataItems = [];
|
||||
@@ -237,6 +238,7 @@ function showLoading(text='加载中...'){
|
||||
function hideLoading(){document.getElementById('globalLoading').style.display='none'}
|
||||
|
||||
async function api(path,opts={}){
|
||||
if(path.startsWith('/api/')) path = API_PREFIX + path.slice(4);
|
||||
const headers = {'Authorization':'Bearer '+TOKEN, ...(opts.headers||{})};
|
||||
if(opts.body && !(opts.body instanceof FormData)){
|
||||
headers['Content-Type']='application/json';
|
||||
@@ -270,7 +272,7 @@ function badgeHtml(status){
|
||||
async function demoLogin(){
|
||||
showLoading('正在登录...');
|
||||
try{
|
||||
const data = await fetch(API+'/api/auth/demo-login',{method:'POST'}).then(r=>r.json());
|
||||
const data = await api('/api/auth/demo-login',{method:'POST'});
|
||||
TOKEN = data.access_token;
|
||||
hideLoading();
|
||||
}catch(e){
|
||||
|
||||
Reference in New Issue
Block a user