@@ -2,7 +2,7 @@ import * as itty from 'itty-router';
2
2
import zod from 'zod' ;
3
3
import { createAnalytics , type Analytics } from './analytics' ;
4
4
import { type ArtifactStorageReader , type ArtifactsType } from './artifact-storage-reader' ;
5
- import { InvalidAuthKeyResponse , MissingAuthKeyResponse , UnexpectedError } from './errors' ;
5
+ import { InvalidAuthKeyResponse , MissingAuthKeyResponse } from './errors' ;
6
6
import { IsAppDeploymentActive } from './is-app-deployment-active' ;
7
7
import type { KeyValidator } from './key-validation' ;
8
8
import { createResponse } from './tracked-response' ;
@@ -13,16 +13,7 @@ export type GetArtifactActionFn = (
13
13
artifactType : ArtifactsType ,
14
14
eTag : string | null ,
15
15
) => Promise <
16
- | { type : 'notModified' }
17
- | { type : 'notFound' }
18
- | { type : 'body' ; body : string }
19
- | {
20
- type : 'redirect' ;
21
- location : {
22
- public : string ;
23
- private : string ;
24
- } ;
25
- }
16
+ { type : 'notModified' } | { type : 'notFound' } | { type : 'response' ; response : Response }
26
17
> ;
27
18
28
19
type ArtifactRequestHandler = {
@@ -161,7 +152,8 @@ export const createArtifactRequestHandler = (deps: ArtifactRequestHandler) => {
161
152
return createResponse ( analytics , 'Not found.' , { status : 404 } , params . targetId , request ) ;
162
153
}
163
154
164
- if ( result . type === 'redirect' ) {
155
+ if ( result . type === 'response' ) {
156
+ const etag = result . response . headers . get ( 'etag' ) ;
165
157
if ( params . artifactType === 'metadata' ) {
166
158
// To not change a lot of logic and still reuse the etag bits, we
167
159
// fetch metadata using the redirect location.
@@ -171,19 +163,8 @@ export const createArtifactRequestHandler = (deps: ArtifactRequestHandler) => {
171
163
// We're using here a private location, because the public S3 endpoint may differ from the internal S3 endpoint. E.g. within a docker network,
172
164
// and we're fetching the artifact from within the private network.
173
165
// If they are the same, private and public locations will be the same.
174
- const metadataResponse = await fetch ( result . location . private ) ;
175
-
176
- if ( ! metadataResponse . ok ) {
177
- console . error (
178
- 'Failed to fetch metadata' ,
179
- metadataResponse . status ,
180
- metadataResponse . statusText ,
181
- ) ;
182
166
183
- return new UnexpectedError ( analytics , request ) ;
184
- }
185
-
186
- const body = await metadataResponse . text ( ) ;
167
+ const body = await result . response . clone ( ) . text ( ) ;
187
168
188
169
// Metadata in SINGLE projects is only Mesh's Metadata, and it always defines _schema
189
170
const isMeshArtifact = body . includes ( `"#/definitions/_schema"` ) ;
@@ -192,7 +173,6 @@ export const createArtifactRequestHandler = (deps: ArtifactRequestHandler) => {
192
173
// Mesh's Metadata shared by Mesh is always an object.
193
174
// The top-level array was caused #3291 and fixed now, but we still need to handle the old data.
194
175
if ( isMeshArtifact && hasTopLevelArray ) {
195
- const etag = metadataResponse . headers . get ( 'etag' ) ;
196
176
return createResponse (
197
177
analytics ,
198
178
body . substring ( 1 , body . length - 1 ) ,
@@ -211,11 +191,17 @@ export const createArtifactRequestHandler = (deps: ArtifactRequestHandler) => {
211
191
212
192
return createResponse (
213
193
analytics ,
214
- 'Found.' ,
215
- // We're using here a public location, because we expose the Location to the end user and
216
- // the public S3 endpoint may differ from the internal S3 endpoint. E.g. within a docker network.
217
- // If they are the same, private and public locations will be the same.
218
- { status : 302 , headers : { Location : result . location . public } } ,
194
+ await result . response . text ( ) ,
195
+ {
196
+ status : 200 ,
197
+ headers : {
198
+ 'Content-Type' :
199
+ params . artifactType === 'metadata' || params . artifactType === 'services'
200
+ ? 'application/json'
201
+ : 'text/plain' ,
202
+ ...( etag ? { etag } : { } ) ,
203
+ } ,
204
+ } ,
219
205
params . targetId ,
220
206
request ,
221
207
) ;
0 commit comments