[feature] Change adminpanel api

This commit is contained in:
Sergey Konovalov
2025-09-08 02:32:28 +03:00
parent bf196e69b9
commit 1e2e74692e
3 changed files with 13 additions and 12 deletions

View File

@ -1,7 +1,7 @@
const BACKEND_URL = process.env.REACT_APP_BACKEND_URL ?? '';
export const fetchStatistics = async () => {
const response = await fetch(`${BACKEND_URL}/info/info.json`);
const response = await fetch(`${BACKEND_URL}/api/v1/admin/stat`);
if (!response.ok) {
throw new Error('Failed to fetch statistics');
}
@ -9,7 +9,7 @@ export const fetchStatistics = async () => {
};
export const fetchConfiguration = async () => {
const response = await fetch(`${BACKEND_URL}/info/config`, {
const response = await fetch(`${BACKEND_URL}/api/v1/admin/config`, {
credentials: 'include'
});
if (!response.ok) {
@ -19,7 +19,7 @@ export const fetchConfiguration = async () => {
};
export const fetchConfigurationSchema = async () => {
const response = await fetch(`${BACKEND_URL}/info/config/schema`, {
const response = await fetch(`${BACKEND_URL}/api/v1/admin/config/schema`, {
credentials: 'include'
});
if (!response.ok) {
@ -29,7 +29,7 @@ export const fetchConfigurationSchema = async () => {
};
export const updateConfiguration = async configData => {
const response = await fetch(`${BACKEND_URL}/info/config`, {
const response = await fetch(`${BACKEND_URL}/api/v1/admin/config`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
@ -59,7 +59,7 @@ export const updateConfiguration = async configData => {
};
export const fetchCurrentUser = async () => {
const response = await fetch(`${BACKEND_URL}/info/adminpanel/me`, {
const response = await fetch(`${BACKEND_URL}/api/v1/admin/me`, {
method: 'GET',
credentials: 'include' // Include cookies in the request
});
@ -75,7 +75,7 @@ export const fetchCurrentUser = async () => {
};
export const login = async ({tenantName, secret}) => {
const response = await fetch(`${BACKEND_URL}/info/adminpanel/login`, {
const response = await fetch(`${BACKEND_URL}/api/v1/admin/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
@ -95,7 +95,7 @@ export const login = async ({tenantName, secret}) => {
};
export const logout = async () => {
const response = await fetch(`${BACKEND_URL}/info/adminpanel/logout`, {
const response = await fetch(`${BACKEND_URL}/api/v1/admin/logout`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'

View File

@ -78,10 +78,9 @@ const corsWithCredentials = cors({
operationContext.global.logger.warn('AdminPanel server starting...');
app.use('/info/config', corsWithCredentials, utils.checkClientIp, configRouter);
app.use('/info/adminpanel', corsWithCredentials, utils.checkClientIp, adminpanelRouter);
// Shared Info router (provides /info.json)
app.use('/info', infoRouter());
app.use('/api/v1/admin/config', corsWithCredentials, utils.checkClientIp, configRouter);
app.use('/api/v1/admin', corsWithCredentials, utils.checkClientIp, adminpanelRouter);
app.get('/api/v1/admin/stat', corsWithCredentials, utils.checkClientIp, infoRouter.licenseInfo);
// todo config or _dirname. Serve AdminPanel client build as static assets
const clientBuildPath = path.resolve('client/build');
@ -95,7 +94,7 @@ function serveSpaIndex(req, res, next) {
// client SPA routes
app.get('*', serveSpaIndex);
app.use((err, req, res) => {
app.use((err, req, res, _next) => {
const ctx = new operationContext.Context();
ctx.initFromRequest(req);
ctx.logger.error('default error handler:%s', err.stack);

View File

@ -241,3 +241,5 @@ function createInfoRouter() {
}
module.exports = createInfoRouter;
// Export handler for reuse
module.exports.licenseInfo = licenseInfo;