From dab4639557c6116c5517a5713d33c375990e44a3 Mon Sep 17 00:00:00 2001 From: Jonas Finnemann Jensen Date: Fri, 8 Nov 2024 12:42:37 +0100 Subject: [PATCH] Write not-found.json to ExportedApi --- app/lib/package/api_export/api_exporter.dart | 9 +++++++++ app/lib/package/api_export/exported_api.dart | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/app/lib/package/api_export/api_exporter.dart b/app/lib/package/api_export/api_exporter.dart index becb38f366..82e72a4e25 100644 --- a/app/lib/package/api_export/api_exporter.dart +++ b/app/lib/package/api_export/api_exporter.dart @@ -147,6 +147,15 @@ class ApiExporter { await synchronizePackageNameCompletionData(); + await _api.notFound.write({ + 'error': { + 'code': 'NotFound', + 'message': 'Package or version requested could not be found.', + }, + 'code': 'NotFound', + 'message': 'Package or version requested could not be found.', + }); + await _api.garbageCollect(allPackageNames); } diff --git a/app/lib/package/api_export/exported_api.dart b/app/lib/package/api_export/exported_api.dart index 5efe290958..e7c5dd51ee 100644 --- a/app/lib/package/api_export/exported_api.dart +++ b/app/lib/package/api_export/exported_api.dart @@ -66,6 +66,15 @@ final class ExportedApi { Duration(hours: 8), ); + /// Interface for writing `/api/not-found.json` which is what the bucket will + /// use as 404 response when serving a website. + ExportedJsonFile> get notFound => + ExportedJsonFile>._( + this, + '/not-found.json', + Duration(minutes: 10), + ); + /// Run garbage collection on the bucket. /// /// This will remove all packages from `latest/` and `/`,