mirror of
https://github.com/dcarrillo/atalaya.git
synced 2026-04-18 02:24:05 +00:00
fix: remove public api endpoint
This commit is contained in:
@@ -182,20 +182,6 @@ describe('worker fetch handler', () => {
|
||||
astroFetchMock.mockResolvedValue(new Response('<html>OK</html>', { status: 200 }));
|
||||
});
|
||||
|
||||
it('should not cache API endpoints', async () => {
|
||||
const worker = await getWorker();
|
||||
const request = new Request('https://example.com/api/status');
|
||||
const envWithPublic = { ...mockEnv, STATUS_PUBLIC: 'true' };
|
||||
|
||||
const response = await worker.fetch(request, envWithPublic, mockCtx);
|
||||
|
||||
// API endpoint returns JSON, not HTML
|
||||
expect(response.headers.get('Content-Type')).toBe('application/json');
|
||||
expect(response.headers.get('Cache-Control')).toBeNull();
|
||||
expect(mockCaches.default.match).not.toHaveBeenCalled();
|
||||
expect(mockCaches.default.put).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should normalize cache key by removing query parameters', async () => {
|
||||
const worker = await getWorker();
|
||||
const request1 = new Request('https://example.com/?t=1234567890');
|
||||
|
||||
18
src/index.ts
18
src/index.ts
@@ -7,7 +7,6 @@ import { parseConfig } from './config/index.js';
|
||||
import { prepareChecks } from './checker/index.js';
|
||||
import { processResults } from './processor/index.js';
|
||||
import { formatWebhookPayload } from './alert/index.js';
|
||||
import { getStatusApiData } from './api/status.js';
|
||||
import { getMonitorStates, writeCheckResults, updateMonitorStates, recordAlert } from './db.js';
|
||||
import { interpolateSecrets } from './utils/interpolate.js';
|
||||
import type { Env } from './types.js';
|
||||
@@ -18,24 +17,7 @@ import type { Config } from './config/types.js';
|
||||
const worker = {
|
||||
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
|
||||
const url = new URL(request.url);
|
||||
if (url.pathname === '/api/status') {
|
||||
try {
|
||||
const configYaml = interpolateSecrets(env.MONITORS_CONFIG, env);
|
||||
const config = parseConfig(configYaml);
|
||||
const data = await getStatusApiData(env.DB, config);
|
||||
return new Response(JSON.stringify(data), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Status API error:', error);
|
||||
return new Response(JSON.stringify({ error: 'Internal Server Error' }), {
|
||||
status: 500,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Auth check for all non-API routes
|
||||
const authResponse = await checkAuth(request, env);
|
||||
if (authResponse) {
|
||||
return authResponse;
|
||||
|
||||
Reference in New Issue
Block a user