Skip to content

Commit b363dd3

Browse files
committed
fix: restore live feed creation flow
1 parent f6e58a9 commit b363dd3

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

app/web/routes/api_v1/metadata_routes.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ def mount_strategies(router)
4242
# @param router [Roda::RodaRequest]
4343
# @return [void]
4444
def mount_root(router)
45+
router.root do
46+
router.get do
47+
render_root_metadata(router)
48+
end
49+
end
50+
4551
router.is do
4652
router.get do
47-
JSON.generate(Api::V1::Response.success(data: Api::V1::RootMetadata.build(router)))
53+
render_root_metadata(router)
4854
end
4955
end
5056
end
@@ -54,6 +60,12 @@ def openapi_spec_path
5460
File.expand_path('../../../../docs/api/v1/openapi.yaml', __dir__)
5561
end
5662

63+
# @param router [Roda::RodaRequest]
64+
# @return [String]
65+
def render_root_metadata(router)
66+
JSON.generate(Api::V1::Response.success(data: Api::V1::RootMetadata.build(router)))
67+
end
68+
5769
# @return [String]
5870
def openapi_spec_contents
5971
return File.read(openapi_spec_path) if File.exist?(openapi_spec_path)

frontend/src/hooks/useApiMetadata.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { useEffect, useState } from 'preact/hooks';
2-
import { getApiMetadata } from '../api/generated';
3-
import { apiClient } from '../api/client';
42
import type { ApiMetadataRecord } from '../api/contracts';
53

64
interface ApiMetadataState {
@@ -23,13 +21,14 @@ export function useApiMetadata() {
2321
setState((prev) => ({ ...prev, isLoading: true, error: null }));
2422

2523
try {
26-
const response = await getApiMetadata({
27-
client: apiClient,
24+
const response = await fetch('/api/v1', {
2825
signal: controller.signal,
26+
headers: { Accept: 'application/json' },
2927
});
30-
const metadata = response.data?.data as unknown as ApiMetadataRecord | undefined;
28+
const payload = (await response.json()) as { success?: boolean; data?: unknown };
29+
const metadata = payload.data as ApiMetadataRecord | undefined;
3130

32-
if (response.error || !response.data?.success || !metadata?.instance) {
31+
if (!response.ok || !payload.success || !metadata?.instance) {
3332
throw new Error('Invalid response format from API metadata');
3433
}
3534

spec/html2rss/web/api/v1_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ def json_feed_headers_tuple
127127
'access_token_required' => true
128128
)
129129
end
130+
131+
it 'returns API information with trailing slash', :aggregate_failures do
132+
get '/api/v1/'
133+
134+
expect(last_response.status).to eq(200)
135+
expect(last_response.content_type).to include('application/json')
136+
137+
json = expect_success_response(last_response)
138+
expect(json.dig('data', 'api', 'name')).to eq('html2rss-web API')
139+
end
130140
end
131141

132142
describe 'GET /api/v1/openapi.yaml', openapi: {

0 commit comments

Comments
 (0)