mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-02-10 18:05:07 +08:00
[feature] Change adminpanel api
This commit is contained in:
@ -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'
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -241,3 +241,5 @@ function createInfoRouter() {
|
||||
}
|
||||
|
||||
module.exports = createInfoRouter;
|
||||
// Export handler for reuse
|
||||
module.exports.licenseInfo = licenseInfo;
|
||||
|
||||
Reference in New Issue
Block a user