fix(mini-user): use Taro.request for analytics and prod API origin
Replace fetch with wx/Taro.request in client-logging for WeChat mini program; point production build to api.dukanghaoke.com. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -9,10 +9,9 @@ const isDevMode =
|
||||
process.argv.includes('development');
|
||||
|
||||
/** 小程序/H5 请求的后端 origin(不含 /api);本地默认本机,生产构建默认远程 */
|
||||
// TODO(prod-release): 发生产前改回 https://api.dukanghaoke.com
|
||||
const API_ORIGIN =
|
||||
process.env.VITE_API_TARGET ??
|
||||
(isDevMode ? 'http://localhost:3000' : 'https://api-test.dukanghaoke.com');
|
||||
(isDevMode ? 'http://localhost:3000' : 'https://api.dukanghaoke.com');
|
||||
|
||||
const requireFromApp = createRequire(path.resolve(__dirname, '../package.json'));
|
||||
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
import Taro from '@tarojs/taro';
|
||||
import { createUserTracker, getSessionId } from '@dukang/client-logging';
|
||||
import { API_BASE, CLIENT_APP, getToken } from './api';
|
||||
|
||||
function currentPagePath(): string | undefined {
|
||||
try {
|
||||
const pages = Taro.getCurrentPages();
|
||||
const cur = pages[pages.length - 1] as { route?: string; $taroPath?: string } | undefined;
|
||||
return cur?.$taroPath || cur?.route || undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
const tracker = createUserTracker({
|
||||
apiBase: API_BASE,
|
||||
clientApp: CLIENT_APP,
|
||||
getToken,
|
||||
getPagePath: currentPagePath,
|
||||
postJson: ({ url, headers, body }) => {
|
||||
void Taro.request({ url, method: 'POST', header: headers, data: body }).catch(() => {});
|
||||
},
|
||||
});
|
||||
|
||||
export { getSessionId };
|
||||
|
||||
Reference in New Issue
Block a user