diff --git a/src/dashboard.html b/src/dashboard.html
index 87470da..b11efde 100644
--- a/src/dashboard.html
+++ b/src/dashboard.html
@@ -715,7 +715,7 @@
abortController = new AbortController();
try {
- let url = '/stats/traffic';
+ let url = '/api/stats/traffic';
if (startTime && endTime) {
url += `?start=${Math.floor(startTime)}&end=${Math.floor(endTime)}`;
} else {
@@ -743,10 +743,10 @@
try {
// Fetch stats and traffic in parallel
const [statsRes, trafficData, uaRes, refRes] = await Promise.all([
- fetch(`/stats/essential?days=${currentDays}`),
+ fetch(`/api/stats/essential?days=${currentDays}`),
fetchTrafficData(),
- fetch('/stats/useragents'),
- fetch('/stats/referers')
+ fetch('/api/stats/useragents'),
+ fetch('/api/stats/referers')
]);
// If traffic fetch was superseded, don't update
@@ -904,10 +904,10 @@
if (currentZoom) {
showLoading(true);
Promise.all([
- fetch(`/stats/essential?days=${currentDays}`),
+ fetch(`/api/stats/essential?days=${currentDays}`),
fetchTrafficData(currentZoom.start, currentZoom.end),
- fetch('/stats/useragents'),
- fetch('/stats/referers')
+ fetch('/api/stats/useragents'),
+ fetch('/api/stats/referers')
]).then(async ([statsRes, trafficData, uaRes, refRes]) => {
if (trafficData === null) {
showLoading(false);
diff --git a/src/routes/api-routes.ts b/src/routes/api-routes.ts
index 80c8e57..e142149 100644
--- a/src/routes/api-routes.ts
+++ b/src/routes/api-routes.ts
@@ -453,9 +453,9 @@ export function createApiRoutes(cache: SlackCache, _slackApp: SlackWrapper) {
),
},
- "/stats/traffic": {
+ "/api/stats/traffic": {
GET: createRoute(
- withAnalytics("/stats/traffic", "GET", handlers.handleGetTraffic),
+ withAnalytics("/api/stats/traffic", "GET", handlers.handleGetTraffic),
{
summary: "Get traffic time-series data",
description:
@@ -510,9 +510,9 @@ export function createApiRoutes(cache: SlackCache, _slackApp: SlackWrapper) {
),
},
- "/stats": {
+ "/api/stats": {
GET: createRoute(
- withAnalytics("/stats", "GET", handlers.handleGetStats),
+ withAnalytics("/api/stats", "GET", handlers.handleGetStats),
{
summary: "Get complete analytics (legacy)",
description:
@@ -544,68 +544,11 @@ export function createApiRoutes(cache: SlackCache, _slackApp: SlackWrapper) {
),
},
- "/stats/essential": {
- GET: createRoute(
- withAnalytics(
- "/stats/essential",
- "GET",
- handlers.handleGetEssentialStats,
- ),
- {
- summary: "Get essential stats",
- description: "Fast-loading essential statistics for the dashboard",
- tags: ["Analytics"],
- parameters: {
- query: [
- queryParam(
- "days",
- "number",
- "Number of days to analyze",
- false,
- 7,
- ),
- ],
- },
- responses: Object.fromEntries([
- apiResponse(200, "Essential stats retrieved", {
- type: "object",
- properties: {
- totalRequests: { type: "number" },
- averageResponseTime: { type: "number" },
- uptime: { type: "number" },
- },
- }),
- ]),
- },
- ),
- },
- "/stats/useragents": {
- GET: createRoute(
- withAnalytics("/stats/useragents", "GET", handlers.handleGetUserAgents),
- {
- summary: "Get user agents",
- description: "Cumulative user agent statistics",
- tags: ["Analytics"],
- responses: Object.fromEntries([
- apiResponse(200, "User agents retrieved", {
- type: "array",
- items: {
- type: "object",
- properties: {
- userAgent: { type: "string" },
- hits: { type: "number" },
- },
- },
- }),
- ]),
- },
- ),
- },
- "/stats/referers": {
+ "/api/stats/referers": {
GET: createRoute(
- withAnalytics("/stats/referers", "GET", handlers.handleGetReferers),
+ withAnalytics("/api/stats/referers", "GET", handlers.handleGetReferers),
{
summary: "Get referer sources",
description: