@edgestore/server 1.0.0-next.0 → 1.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/dist/adapters/astro/index.d.ts +7 -12
- package/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +14 -161
- package/dist/adapters/dispatcher.d.ts +30 -0
- package/dist/adapters/dispatcher.d.ts.map +1 -0
- package/dist/adapters/dispatcher.js +172 -0
- package/dist/adapters/express/index.d.ts +7 -12
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +24 -94
- package/dist/adapters/fastify/index.d.ts +7 -12
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +23 -121
- package/dist/adapters/hono/index.d.ts +7 -12
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +14 -121
- package/dist/adapters/next/app/index.d.ts +7 -12
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +21 -148
- package/dist/adapters/next/pages/index.d.ts +7 -12
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +34 -95
- package/dist/adapters/remix/index.d.ts +7 -12
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +14 -136
- package/dist/adapters/shared.d.ts +140 -55
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +188 -179
- package/dist/adapters/start/index.d.ts +7 -12
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +14 -169
- package/dist/core/client/bucketClient.d.ts +7 -0
- package/dist/core/client/bucketClient.d.ts.map +1 -0
- package/dist/core/client/bucketClient.js +312 -0
- package/dist/core/client/index.d.ts +120 -142
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +13 -218
- package/dist/core/index.d.ts +20 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +14 -2
- package/dist/core/provider.d.ts +15 -0
- package/dist/core/provider.d.ts.map +1 -0
- package/dist/core/provider.js +25 -0
- package/dist/core/routerRules.d.ts +20 -0
- package/dist/core/routerRules.d.ts.map +1 -0
- package/dist/core/routerRules.js +42 -0
- package/dist/core/validateFile.d.ts +9 -0
- package/dist/core/validateFile.d.ts.map +1 -0
- package/dist/core/validateFile.js +43 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/libs/env.d.ts +3 -0
- package/dist/libs/env.d.ts.map +1 -0
- package/dist/libs/env.js +14 -0
- package/dist/libs/logger.d.ts +2 -1
- package/dist/libs/logger.d.ts.map +1 -1
- package/dist/libs/logger.js +1 -1
- package/dist/providers/azure-blob/index.d.ts +119 -0
- package/dist/providers/azure-blob/index.d.ts.map +1 -0
- package/dist/providers/azure-blob/index.js +166 -0
- package/dist/providers/edgestore/index.d.ts +171 -3
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +304 -136
- package/dist/providers/{aws → s3}/index.d.ts +68 -11
- package/dist/providers/s3/index.d.ts.map +1 -0
- package/dist/providers/s3/index.js +146 -0
- package/dist/test-utils/edgestoreSmoke.d.ts +0 -2
- package/dist/test-utils/edgestoreSmoke.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +17 -20
- package/providers/azure-blob/index.d.ts +1 -0
- package/providers/azure-blob/index.js +1 -0
- package/providers/s3/index.d.ts +1 -0
- package/providers/s3/index.js +1 -0
- package/src/adapters/astro/index.ts +27 -211
- package/src/adapters/dispatcher.ts +261 -0
- package/src/adapters/express/index.ts +43 -149
- package/src/adapters/fastify/index.ts +43 -191
- package/src/adapters/hono/index.ts +28 -183
- package/src/adapters/next/app/index.ts +37 -201
- package/src/adapters/next/pages/index.ts +55 -156
- package/src/adapters/remix/index.ts +27 -190
- package/src/adapters/shared.ts +237 -261
- package/src/adapters/start/index.ts +28 -200
- package/src/core/client/bucketClient.ts +476 -0
- package/src/core/client/index.ts +301 -428
- package/src/core/index.ts +42 -1
- package/src/core/provider.ts +80 -0
- package/src/core/routerRules.ts +63 -0
- package/src/core/validateFile.ts +50 -0
- package/src/index.ts +10 -0
- package/src/libs/env.ts +16 -0
- package/src/libs/logger.ts +4 -2
- package/src/providers/azure-blob/index.ts +265 -0
- package/src/providers/edgestore/index.ts +426 -154
- package/src/providers/s3/index.ts +289 -0
- package/src/test-utils/edgestoreSmoke.ts +0 -11
- package/src/version.ts +1 -1
- package/dist/core/sdk/index.d.ts +0 -282
- package/dist/core/sdk/index.d.ts.map +0 -1
- package/dist/core/sdk/index.js +0 -253
- package/dist/providers/aws/index.d.ts.map +0 -1
- package/dist/providers/aws/index.js +0 -102
- package/dist/providers/azure/index.d.ts +0 -39
- package/dist/providers/azure/index.d.ts.map +0 -1
- package/dist/providers/azure/index.js +0 -84
- package/dist/version.js +0 -4
- package/providers/aws/index.d.ts +0 -1
- package/providers/aws/index.js +0 -1
- package/providers/azure/index.d.ts +0 -1
- package/providers/azure/index.js +0 -1
- package/src/core/sdk/index.ts +0 -542
- package/src/providers/aws/index.ts +0 -239
- package/src/providers/azure/index.ts +0 -141
|
@@ -1,219 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EDGE_STORE_ERROR_CODES,
|
|
3
|
-
EdgeStoreError,
|
|
4
|
-
type EdgeStoreErrorCodeKey,
|
|
5
|
-
type EdgeStoreRouter,
|
|
6
|
-
type MaybePromise,
|
|
7
|
-
type Provider,
|
|
8
|
-
} from '@edgestore/shared';
|
|
1
|
+
import { EdgeStoreError, type AnyContext } from '@edgestore/shared';
|
|
9
2
|
import { type NextRequest } from 'next/server';
|
|
10
3
|
import Logger, { type LogLevel } from '../../../libs/logger';
|
|
11
|
-
import { matchPath } from '../../../libs/utils';
|
|
12
|
-
import { EdgeStoreProvider } from '../../../providers/edgestore';
|
|
13
4
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
init,
|
|
20
|
-
requestUpload,
|
|
21
|
-
requestUploadParts,
|
|
22
|
-
type CompleteMultipartUploadBody,
|
|
23
|
-
type ConfirmUploadBody,
|
|
24
|
-
type CookieConfig,
|
|
25
|
-
type DeleteFileBody,
|
|
26
|
-
type RequestUploadBody,
|
|
27
|
-
type RequestUploadPartsParams,
|
|
28
|
-
} from '../../shared';
|
|
5
|
+
dispatchEdgeStoreRequest,
|
|
6
|
+
resolveContext,
|
|
7
|
+
type CreateContextConfig,
|
|
8
|
+
} from '../../dispatcher';
|
|
9
|
+
import { type CookieConfig, type HandlerEdgeStore } from '../../shared';
|
|
29
10
|
|
|
30
11
|
export type CreateContextOptions = {
|
|
31
12
|
req: NextRequest;
|
|
32
13
|
};
|
|
33
14
|
|
|
34
|
-
export type Config<TCtx> = {
|
|
35
|
-
|
|
36
|
-
router: EdgeStoreRouter<TCtx>;
|
|
15
|
+
export type Config<TCtx extends AnyContext> = {
|
|
16
|
+
edgestore: HandlerEdgeStore<TCtx>;
|
|
37
17
|
logLevel?: LogLevel;
|
|
38
18
|
cookieConfig?: CookieConfig;
|
|
39
|
-
} &
|
|
40
|
-
? object
|
|
41
|
-
: {
|
|
42
|
-
provider?: Provider;
|
|
43
|
-
router: EdgeStoreRouter<TCtx>;
|
|
44
|
-
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
45
|
-
cookieConfig?: CookieConfig;
|
|
46
|
-
});
|
|
19
|
+
} & CreateContextConfig<TCtx, CreateContextOptions>;
|
|
47
20
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
53
|
-
const { provider = EdgeStoreProvider(), cookieConfig } = config;
|
|
21
|
+
export function createEdgeStoreNextHandler<TCtx extends AnyContext>(
|
|
22
|
+
config: Config<TCtx>,
|
|
23
|
+
) {
|
|
24
|
+
const { cookieConfig } = config;
|
|
54
25
|
const log = new Logger(config.logLevel);
|
|
55
|
-
globalThis._EDGE_STORE_LOGGER = log;
|
|
56
26
|
log.debug('Creating EdgeStore Next handler (app adapter)');
|
|
57
27
|
|
|
58
|
-
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
59
|
-
|
|
60
28
|
return async (req: NextRequest) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const pathname = req.nextUrl.pathname;
|
|
70
|
-
|
|
71
|
-
if (matchPath(pathname, '/health')) {
|
|
72
|
-
return new Response('OK', {
|
|
73
|
-
status: 200,
|
|
74
|
-
});
|
|
75
|
-
} else if (matchPath(pathname, '/init')) {
|
|
76
|
-
let ctx = {} as TCtx;
|
|
77
|
-
try {
|
|
78
|
-
ctx =
|
|
79
|
-
'createContext' in config
|
|
80
|
-
? await config.createContext({ req })
|
|
81
|
-
: ({} as TCtx);
|
|
82
|
-
} catch (err) {
|
|
83
|
-
throw new EdgeStoreError({
|
|
84
|
-
message: 'Error creating context',
|
|
85
|
-
code: 'CREATE_CONTEXT_ERROR',
|
|
86
|
-
cause: err instanceof Error ? err : undefined,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const { newCookies, ...body } = await init({
|
|
90
|
-
ctx,
|
|
91
|
-
provider,
|
|
92
|
-
router: config.router,
|
|
93
|
-
cookieConfig,
|
|
94
|
-
});
|
|
95
|
-
const res = new Response(JSON.stringify(body), {
|
|
96
|
-
status: 200,
|
|
97
|
-
headers: {
|
|
98
|
-
'Content-Type': 'application/json',
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
for (const cookie of newCookies) {
|
|
102
|
-
res.headers.append('Set-Cookie', cookie);
|
|
103
|
-
}
|
|
104
|
-
return res;
|
|
105
|
-
} else if (matchPath(pathname, '/request-upload')) {
|
|
106
|
-
const res = await requestUpload({
|
|
107
|
-
provider,
|
|
108
|
-
router: config.router,
|
|
109
|
-
body: (await req.json()) as RequestUploadBody,
|
|
110
|
-
ctxToken: req.cookies.get(resolvedCookieConfig.ctx.name)?.value,
|
|
111
|
-
});
|
|
112
|
-
return new Response(JSON.stringify(res), {
|
|
113
|
-
status: 200,
|
|
114
|
-
headers: {
|
|
115
|
-
'Content-Type': 'application/json',
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
119
|
-
const res = await requestUploadParts({
|
|
120
|
-
provider,
|
|
121
|
-
router: config.router,
|
|
122
|
-
body: (await req.json()) as RequestUploadPartsParams,
|
|
123
|
-
ctxToken: req.cookies.get(resolvedCookieConfig.ctx.name)?.value,
|
|
124
|
-
});
|
|
125
|
-
return new Response(JSON.stringify(res), {
|
|
126
|
-
status: 200,
|
|
127
|
-
headers: {
|
|
128
|
-
'Content-Type': 'application/json',
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
132
|
-
await completeMultipartUpload({
|
|
133
|
-
provider,
|
|
134
|
-
router: config.router,
|
|
135
|
-
body: (await req.json()) as CompleteMultipartUploadBody,
|
|
136
|
-
ctxToken: req.cookies.get(resolvedCookieConfig.ctx.name)?.value,
|
|
137
|
-
});
|
|
138
|
-
return new Response(null, {
|
|
139
|
-
status: 200,
|
|
140
|
-
});
|
|
141
|
-
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
142
|
-
const res = await confirmUpload({
|
|
143
|
-
provider,
|
|
144
|
-
router: config.router,
|
|
145
|
-
body: (await req.json()) as ConfirmUploadBody,
|
|
146
|
-
ctxToken: req.cookies.get(resolvedCookieConfig.ctx.name)?.value,
|
|
147
|
-
});
|
|
148
|
-
return new Response(JSON.stringify(res), {
|
|
149
|
-
status: 200,
|
|
150
|
-
headers: {
|
|
151
|
-
'Content-Type': 'application/json',
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
} else if (matchPath(pathname, '/delete-file')) {
|
|
155
|
-
const res = await deleteFile({
|
|
156
|
-
provider,
|
|
157
|
-
router: config.router,
|
|
158
|
-
body: (await req.json()) as DeleteFileBody,
|
|
159
|
-
ctxToken: req.cookies.get(resolvedCookieConfig.ctx.name)?.value,
|
|
160
|
-
});
|
|
161
|
-
return new Response(JSON.stringify(res), {
|
|
162
|
-
status: 200,
|
|
163
|
-
headers: {
|
|
164
|
-
'Content-Type': 'application/json',
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
168
|
-
const url = req.nextUrl.searchParams.get('url');
|
|
169
|
-
if (typeof url === 'string') {
|
|
170
|
-
const proxyRes = await fetchProxyFile({
|
|
171
|
-
cookieHeader: req.cookies.toString(),
|
|
172
|
-
url,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
return new Response(proxyRes.body, {
|
|
176
|
-
status: proxyRes.status,
|
|
177
|
-
headers: {
|
|
178
|
-
'Content-Type': proxyRes.contentType,
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
} else {
|
|
182
|
-
return new Response(null, {
|
|
183
|
-
status: 400,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
} else {
|
|
187
|
-
return new Response(null, {
|
|
188
|
-
status: 404,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
} catch (err) {
|
|
192
|
-
if (err instanceof EdgeStoreError) {
|
|
193
|
-
log[err.level](err.formattedMessage());
|
|
194
|
-
if (err.cause) log[err.level](err.cause);
|
|
195
|
-
return new Response(JSON.stringify(err.formattedJson()), {
|
|
196
|
-
status: EDGE_STORE_ERROR_CODES[err.code as EdgeStoreErrorCodeKey],
|
|
197
|
-
headers: {
|
|
198
|
-
'Content-Type': 'application/json',
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
log.error(err);
|
|
203
|
-
return new Response(
|
|
204
|
-
JSON.stringify(
|
|
205
|
-
new EdgeStoreError({
|
|
206
|
-
message: 'Internal server error',
|
|
207
|
-
code: 'SERVER_ERROR',
|
|
208
|
-
}).formattedJson(),
|
|
209
|
-
),
|
|
210
|
-
{
|
|
211
|
-
status: 500,
|
|
212
|
-
headers: {
|
|
213
|
-
'Content-Type': 'application/json',
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
);
|
|
29
|
+
if (!('nextUrl' in req)) {
|
|
30
|
+
const error = new EdgeStoreError({
|
|
31
|
+
message:
|
|
32
|
+
'Error running the app adapter. Make sure you are importing the correct adapter in your router configuration',
|
|
33
|
+
code: 'SERVER_ERROR',
|
|
34
|
+
});
|
|
35
|
+
return Response.json(error.formattedJson(), { status: 500 });
|
|
217
36
|
}
|
|
37
|
+
|
|
38
|
+
return await dispatchEdgeStoreRequest<TCtx>({
|
|
39
|
+
edgestore: config.edgestore,
|
|
40
|
+
logger: log,
|
|
41
|
+
cookieConfig,
|
|
42
|
+
request: {
|
|
43
|
+
pathname: req.nextUrl.pathname,
|
|
44
|
+
readJson: () => req.json(),
|
|
45
|
+
getQuery: (name) => req.nextUrl.searchParams.get(name) ?? undefined,
|
|
46
|
+
cookieHeader:
|
|
47
|
+
req.headers?.get('cookie') ?? (req.cookies.toString() || undefined),
|
|
48
|
+
createContext: () =>
|
|
49
|
+
resolveContext<TCtx, CreateContextOptions>(config, {
|
|
50
|
+
req,
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
});
|
|
218
54
|
};
|
|
219
55
|
}
|
|
@@ -1,176 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EDGE_STORE_ERROR_CODES,
|
|
3
|
-
EdgeStoreError,
|
|
4
|
-
type EdgeStoreErrorCodeKey,
|
|
5
|
-
type EdgeStoreRouter,
|
|
6
|
-
type MaybePromise,
|
|
7
|
-
type Provider,
|
|
8
|
-
} from '@edgestore/shared';
|
|
1
|
+
import { EdgeStoreError, type AnyContext } from '@edgestore/shared';
|
|
9
2
|
import { type NextApiRequest, type NextApiResponse } from 'next/types';
|
|
10
3
|
import Logger, { type LogLevel } from '../../../libs/logger';
|
|
11
|
-
import { matchPath } from '../../../libs/utils';
|
|
12
|
-
import { EdgeStoreProvider } from '../../../providers/edgestore';
|
|
13
4
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
requestUpload,
|
|
21
|
-
requestUploadParts,
|
|
22
|
-
type CompleteMultipartUploadBody,
|
|
23
|
-
type ConfirmUploadBody,
|
|
24
|
-
type CookieConfig,
|
|
25
|
-
type DeleteFileBody,
|
|
26
|
-
type RequestUploadBody,
|
|
27
|
-
type RequestUploadPartsParams,
|
|
28
|
-
} from '../../shared';
|
|
5
|
+
dispatchEdgeStoreRequest,
|
|
6
|
+
resolveContext,
|
|
7
|
+
toNodeDispatchResponse,
|
|
8
|
+
type CreateContextConfig,
|
|
9
|
+
} from '../../dispatcher';
|
|
10
|
+
import type { CookieConfig, HandlerEdgeStore } from '../../shared';
|
|
29
11
|
|
|
30
12
|
export type CreateContextOptions = {
|
|
31
13
|
req: NextApiRequest;
|
|
32
14
|
res: NextApiResponse;
|
|
33
15
|
};
|
|
34
16
|
|
|
35
|
-
export type Config<TCtx> = {
|
|
36
|
-
|
|
37
|
-
router: EdgeStoreRouter<TCtx>;
|
|
17
|
+
export type Config<TCtx extends AnyContext> = {
|
|
18
|
+
edgestore: HandlerEdgeStore<TCtx>;
|
|
38
19
|
logLevel?: LogLevel;
|
|
39
20
|
cookieConfig?: CookieConfig;
|
|
40
|
-
} &
|
|
41
|
-
? object
|
|
42
|
-
: {
|
|
43
|
-
provider?: Provider;
|
|
44
|
-
router: EdgeStoreRouter<TCtx>;
|
|
45
|
-
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
46
|
-
cookieConfig?: CookieConfig;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
declare const globalThis: {
|
|
50
|
-
_EDGE_STORE_LOGGER: Logger;
|
|
51
|
-
};
|
|
21
|
+
} & CreateContextConfig<TCtx, CreateContextOptions>;
|
|
52
22
|
|
|
53
|
-
export function createEdgeStoreNextHandler<TCtx>(
|
|
54
|
-
|
|
23
|
+
export function createEdgeStoreNextHandler<TCtx extends AnyContext>(
|
|
24
|
+
config: Config<TCtx>,
|
|
25
|
+
) {
|
|
55
26
|
const log = new Logger(config.logLevel);
|
|
56
|
-
globalThis._EDGE_STORE_LOGGER = log;
|
|
57
27
|
log.debug('Creating EdgeStore Next handler (pages adapter)');
|
|
58
28
|
|
|
59
|
-
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
60
|
-
|
|
61
29
|
return async (req: NextApiRequest, res: NextApiResponse) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
res.send('OK');
|
|
72
|
-
} else if (matchPath(pathname, '/init')) {
|
|
73
|
-
let ctx = {} as TCtx;
|
|
74
|
-
try {
|
|
75
|
-
ctx =
|
|
76
|
-
'createContext' in config
|
|
77
|
-
? await config.createContext({ req, res })
|
|
78
|
-
: ({} as TCtx);
|
|
79
|
-
} catch (err) {
|
|
80
|
-
throw new EdgeStoreError({
|
|
81
|
-
message: 'Error creating context',
|
|
82
|
-
code: 'CREATE_CONTEXT_ERROR',
|
|
83
|
-
cause: err instanceof Error ? err : undefined,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
const { newCookies, ...body } = await init({
|
|
87
|
-
ctx,
|
|
88
|
-
provider,
|
|
89
|
-
router: config.router,
|
|
90
|
-
cookieConfig,
|
|
91
|
-
});
|
|
92
|
-
res.setHeader('Set-Cookie', newCookies);
|
|
93
|
-
res.json(body);
|
|
94
|
-
} else if (matchPath(pathname, '/request-upload')) {
|
|
95
|
-
res.json(
|
|
96
|
-
await requestUpload({
|
|
97
|
-
provider,
|
|
98
|
-
router: config.router,
|
|
99
|
-
body: req.body as RequestUploadBody,
|
|
100
|
-
ctxToken: req.cookies[resolvedCookieConfig.ctx.name],
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
103
|
-
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
104
|
-
res.json(
|
|
105
|
-
await requestUploadParts({
|
|
106
|
-
provider,
|
|
107
|
-
router: config.router,
|
|
108
|
-
body: req.body as RequestUploadPartsParams,
|
|
109
|
-
ctxToken: req.cookies[resolvedCookieConfig.ctx.name],
|
|
110
|
-
}),
|
|
111
|
-
);
|
|
112
|
-
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
113
|
-
await completeMultipartUpload({
|
|
114
|
-
provider,
|
|
115
|
-
router: config.router,
|
|
116
|
-
body: req.body as CompleteMultipartUploadBody,
|
|
117
|
-
ctxToken: req.cookies[resolvedCookieConfig.ctx.name],
|
|
118
|
-
});
|
|
119
|
-
res.status(200).end();
|
|
120
|
-
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
121
|
-
res.json(
|
|
122
|
-
await confirmUpload({
|
|
123
|
-
provider,
|
|
124
|
-
router: config.router,
|
|
125
|
-
body: req.body as ConfirmUploadBody,
|
|
126
|
-
ctxToken: req.cookies[resolvedCookieConfig.ctx.name],
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
129
|
-
} else if (matchPath(pathname, '/delete-file')) {
|
|
130
|
-
res.json(
|
|
131
|
-
await deleteFile({
|
|
132
|
-
provider,
|
|
133
|
-
router: config.router,
|
|
134
|
-
body: req.body as DeleteFileBody,
|
|
135
|
-
ctxToken: req.cookies[resolvedCookieConfig.ctx.name],
|
|
136
|
-
}),
|
|
137
|
-
);
|
|
138
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
139
|
-
const { url } = req.query;
|
|
140
|
-
if (typeof url === 'string') {
|
|
141
|
-
const proxyRes = await fetchProxyFile({
|
|
142
|
-
cookieHeader: req.headers.cookie,
|
|
143
|
-
url,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
res.setHeader('Content-Type', proxyRes.contentType);
|
|
30
|
+
if (!('json' in (res as object))) {
|
|
31
|
+
const error = new EdgeStoreError({
|
|
32
|
+
message:
|
|
33
|
+
'Error running the pages adapter. Make sure you are importing the correct adapter in your router configuration',
|
|
34
|
+
code: 'SERVER_ERROR',
|
|
35
|
+
});
|
|
36
|
+
res.status(500).json(error.formattedJson());
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
147
39
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
40
|
+
const url = new URL(req.url ?? '', 'http://edgestore.local');
|
|
41
|
+
const response = await dispatchEdgeStoreRequest<TCtx>({
|
|
42
|
+
edgestore: config.edgestore,
|
|
43
|
+
logger: log,
|
|
44
|
+
cookieConfig: config.cookieConfig,
|
|
45
|
+
request: {
|
|
46
|
+
pathname: url.pathname,
|
|
47
|
+
readJson: async () => req.body,
|
|
48
|
+
getQuery: (name) => {
|
|
49
|
+
const value = req.query[name];
|
|
50
|
+
return typeof value === 'string'
|
|
51
|
+
? value
|
|
52
|
+
: (url.searchParams.get(name) ?? undefined);
|
|
53
|
+
},
|
|
54
|
+
cookieHeader: req.headers.cookie,
|
|
55
|
+
cookies: req.cookies,
|
|
56
|
+
createContext: () =>
|
|
57
|
+
resolveContext<TCtx, CreateContextOptions>(config, {
|
|
58
|
+
req,
|
|
59
|
+
res,
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const normalized = await toNodeDispatchResponse(response);
|
|
64
|
+
for (const [name, value] of normalized.headers) {
|
|
65
|
+
res.setHeader(name, value);
|
|
66
|
+
}
|
|
67
|
+
res.status(normalized.status);
|
|
68
|
+
if (normalized.body === undefined) {
|
|
69
|
+
res.end();
|
|
70
|
+
return;
|
|
174
71
|
}
|
|
72
|
+
if (normalized.isJson) res.json(normalized.body);
|
|
73
|
+
else res.end(normalized.body);
|
|
175
74
|
};
|
|
176
75
|
}
|