mirror of
https://github.com/ether/etherpad-lite.git
synced 2026-01-23 02:35:34 +00:00
feat: disable stats endpoint if enableMetrics is false
This commit is contained in:
parent
45a906e19d
commit
40884fa96b
11 changed files with 462 additions and 647 deletions
|
|
@ -9,22 +9,29 @@ export const ShoutPage = ()=>{
|
|||
const [message, setMessage] = useState<string>("");
|
||||
const [sticky, setSticky] = useState<boolean>(false);
|
||||
const socket = useStore(state => state.settingsSocket);
|
||||
const pluginSocket = useStore(state => state.pluginsSocket);
|
||||
const [shouts, setShouts] = useState<ShoutType[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/stats')
|
||||
.then(response => response.json())
|
||||
.then(data => setTotalUsers(data.totalUsers));
|
||||
}, []);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if(socket) {
|
||||
if(socket && pluginSocket) {
|
||||
console.log('Socket connected', socket.id);
|
||||
socket.on('shout', (shout) => {
|
||||
setShouts([...shouts, shout])
|
||||
})
|
||||
pluginSocket.on('results:stats', (statData) => {
|
||||
console.log('Shoutdata', statData);
|
||||
setTotalUsers(statData.totalUsers);
|
||||
})
|
||||
}
|
||||
}, [socket, shouts])
|
||||
}, [socket, shouts, pluginSocket])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (pluginSocket) {
|
||||
pluginSocket.emit('getStats', {});
|
||||
}
|
||||
}, [pluginSocket]);
|
||||
|
||||
const sendMessage = () => {
|
||||
socket?.emit('shout', {
|
||||
|
|
|
|||
|
|
@ -28,10 +28,6 @@ export default defineConfig({
|
|||
'/admin-auth/': {
|
||||
target: 'http://localhost:9001',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/stats': {
|
||||
target: 'http://localhost:9001',
|
||||
changeOrigin: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,8 @@
|
|||
"docs:dev": "vitepress dev",
|
||||
"docs:build": "vitepress build",
|
||||
"docs:preview": "vitepress preview"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"search-insights": "^2.17.3"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1036
pnpm-lock.yaml
generated
1036
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
|
@ -171,6 +171,14 @@
|
|||
*/
|
||||
"showSettingsInAdminPage": "${SHOW_SETTINGS_IN_ADMIN_PAGE:true}",
|
||||
|
||||
/*
|
||||
* Enable/disable the metrics endpoint.
|
||||
*
|
||||
* This is used by the monitoring plugins to collect metrics about Etherpad.
|
||||
* If you do not use any monitoring plugins, you can disable this.
|
||||
*/
|
||||
"enableMetrics": ${ENABLE_METRICS:true},
|
||||
|
||||
/*
|
||||
* Settings for cleanup of pads
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -162,6 +162,14 @@
|
|||
*/
|
||||
"showSettingsInAdminPage": true,
|
||||
|
||||
/*
|
||||
* Enable/disable the metrics endpoint.
|
||||
*
|
||||
* This is used by the monitoring plugins to collect metrics about Etherpad.
|
||||
* If you do not use any monitoring plugins, you can disable this.
|
||||
*/
|
||||
"enableMetrics": ${ENABLE_METRICS:true},
|
||||
|
||||
/*
|
||||
* Settings for cleanup of pads
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ exports.restartServer = async () => {
|
|||
// Give plugins an opportunity to install handlers/middleware before the express-session
|
||||
// middleware. This allows plugins to avoid creating an express-session record in the database
|
||||
// when it is not needed (e.g., public static content).
|
||||
await hooks.aCallAll('expressPreSession', {app});
|
||||
await hooks.aCallAll('expressPreSession', {app, settings});
|
||||
app.use(exports.sessionMiddleware);
|
||||
|
||||
app.use(webaccess.checkAccess);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
|
|||
})
|
||||
}
|
||||
|
||||
socket.on('getStats', ()=>{
|
||||
console.log("Getting stats for admin plugins");
|
||||
socket.emit('results:stats', require('../../stats').toJSON());
|
||||
})
|
||||
|
||||
socket.on('getInstalled', async (query: string) => {
|
||||
// send currently installed plugins
|
||||
const installed =
|
||||
|
|
@ -53,6 +58,7 @@ exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
|
|||
socket.emit('results:installed', {installed});
|
||||
});
|
||||
|
||||
|
||||
socket.on('checkUpdates', async () => {
|
||||
// Check plugins for updates
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ exports.socketio = (hookName: string, {io}: any) => {
|
|||
}
|
||||
|
||||
|
||||
exports.expressPreSession = async (hookName:string, {app}:ArgsExpressType) => {
|
||||
exports.expressPreSession = async (hookName:string, {app, settings}:ArgsExpressType) => {
|
||||
// This endpoint is intended to conform to:
|
||||
// https://www.ietf.org/archive/id/draft-inadarei-api-health-check-06.html
|
||||
app.get('/health', (req:any, res:any) => {
|
||||
|
|
@ -31,9 +31,12 @@ exports.expressPreSession = async (hookName:string, {app}:ArgsExpressType) => {
|
|||
});
|
||||
});
|
||||
|
||||
app.get('/stats', (req:any, res:any) => {
|
||||
res.json(require('../../stats').toJSON());
|
||||
});
|
||||
if (settings.enableMetrics) {
|
||||
app.get('/stats', (req:any, res:any) => {
|
||||
res.json(require('../../stats').toJSON());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
app.get('/javascript', (req:any, res:any) => {
|
||||
res.send(eejs.require('ep_etherpad-lite/templates/javascript.html', {req}));
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import {Express} from "express";
|
||||
import {MapArrayType} from "./MapType";
|
||||
|
||||
export type ArgsExpressType = {
|
||||
app:Express,
|
||||
io: any,
|
||||
server:any
|
||||
settings: MapArrayType<any>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,6 +205,12 @@ exports.padOptions = {
|
|||
lang: null,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Wether to enable the /stats endpoint. The functionality in the admin menu is untouched for this.
|
||||
*/
|
||||
exports.enableMetrics = true
|
||||
|
||||
/**
|
||||
* Whether certain shortcut keys are enabled for a user in the pad
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue