@edgestore/server 0.8.0 → 1.0.0-next.0

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.
Files changed (89) hide show
  1. package/adapters/astro/index.d.ts +1 -1
  2. package/adapters/astro/index.js +1 -1
  3. package/adapters/express/index.d.ts +1 -1
  4. package/adapters/express/index.js +1 -1
  5. package/adapters/fastify/index.d.ts +1 -1
  6. package/adapters/fastify/index.js +1 -1
  7. package/adapters/hono/index.d.ts +1 -1
  8. package/adapters/hono/index.js +1 -1
  9. package/adapters/next/app/index.d.ts +1 -1
  10. package/adapters/next/app/index.js +1 -1
  11. package/adapters/next/pages/index.d.ts +1 -1
  12. package/adapters/next/pages/index.js +1 -1
  13. package/adapters/remix/index.d.ts +1 -1
  14. package/adapters/remix/index.js +1 -1
  15. package/adapters/start/index.d.ts +1 -1
  16. package/adapters/start/index.js +1 -1
  17. package/core/index.d.ts +1 -1
  18. package/core/index.js +1 -1
  19. package/dist/adapters/astro/index.d.ts +2 -2
  20. package/dist/adapters/astro/index.js +28 -30
  21. package/dist/adapters/express/index.d.ts +2 -2
  22. package/dist/adapters/express/index.js +28 -30
  23. package/dist/adapters/fastify/index.d.ts +2 -2
  24. package/dist/adapters/fastify/index.js +28 -30
  25. package/dist/adapters/hono/index.d.ts +2 -2
  26. package/dist/adapters/hono/index.js +28 -30
  27. package/dist/adapters/imageTypes.js +1 -3
  28. package/dist/adapters/next/app/index.d.ts +2 -2
  29. package/dist/adapters/next/app/index.js +29 -31
  30. package/dist/adapters/next/pages/index.d.ts +2 -2
  31. package/dist/adapters/next/pages/index.js +29 -31
  32. package/dist/adapters/remix/index.d.ts +2 -2
  33. package/dist/adapters/remix/index.js +28 -30
  34. package/dist/adapters/shared.d.ts.map +1 -1
  35. package/dist/adapters/shared.js +44 -50
  36. package/dist/adapters/start/index.d.ts +2 -2
  37. package/dist/adapters/start/index.js +28 -30
  38. package/dist/core/client/index.d.ts.map +1 -1
  39. package/dist/core/client/index.js +7 -9
  40. package/dist/core/index.d.ts +2 -2
  41. package/dist/core/index.js +2 -10
  42. package/dist/core/sdk/index.d.ts.map +1 -1
  43. package/dist/core/sdk/index.js +10 -13
  44. package/dist/index.js +1 -10
  45. package/dist/libs/errors/EdgeStoreCredentialsError.js +1 -3
  46. package/dist/libs/logger.js +5 -9
  47. package/dist/libs/utils.js +1 -3
  48. package/dist/providers/aws/index.d.ts.map +1 -1
  49. package/dist/providers/aws/index.js +12 -15
  50. package/dist/providers/azure/index.d.ts.map +1 -1
  51. package/dist/providers/azure/index.js +6 -9
  52. package/dist/providers/edgestore/index.js +12 -14
  53. package/dist/version.d.ts +1 -1
  54. package/dist/version.d.ts.map +1 -1
  55. package/dist/version.js +2 -5
  56. package/package.json +51 -50
  57. package/providers/aws/index.d.ts +1 -1
  58. package/providers/aws/index.js +1 -1
  59. package/providers/azure/index.d.ts +1 -1
  60. package/providers/azure/index.js +1 -1
  61. package/providers/edgestore/index.d.ts +1 -1
  62. package/providers/edgestore/index.js +1 -1
  63. package/src/adapters/shared.ts +12 -13
  64. package/src/core/client/index.ts +0 -1
  65. package/src/core/sdk/index.ts +1 -8
  66. package/src/providers/aws/index.ts +1 -2
  67. package/src/providers/azure/index.ts +1 -2
  68. package/src/version.ts +1 -1
  69. package/dist/adapters/astro/index.mjs +0 -172
  70. package/dist/adapters/express/index.mjs +0 -108
  71. package/dist/adapters/fastify/index.mjs +0 -135
  72. package/dist/adapters/hono/index.mjs +0 -131
  73. package/dist/adapters/imageTypes.mjs +0 -12
  74. package/dist/adapters/next/app/index.mjs +0 -163
  75. package/dist/adapters/next/pages/index.mjs +0 -112
  76. package/dist/adapters/remix/index.mjs +0 -148
  77. package/dist/adapters/shared.mjs +0 -471
  78. package/dist/adapters/start/index.mjs +0 -181
  79. package/dist/core/client/index.mjs +0 -221
  80. package/dist/core/index.mjs +0 -2
  81. package/dist/core/sdk/index.mjs +0 -253
  82. package/dist/index.mjs +0 -1
  83. package/dist/libs/errors/EdgeStoreCredentialsError.mjs +0 -10
  84. package/dist/libs/logger.mjs +0 -53
  85. package/dist/libs/utils.mjs +0 -10
  86. package/dist/providers/aws/index.mjs +0 -103
  87. package/dist/providers/azure/index.mjs +0 -85
  88. package/dist/providers/edgestore/index.mjs +0 -164
  89. package/dist/version.mjs +0 -4
@@ -1,172 +0,0 @@
1
- import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
2
- import Logger from '../../libs/logger.mjs';
3
- import { matchPath } from '../../libs/utils.mjs';
4
- import { EdgeStoreProvider } from '../../providers/edgestore/index.mjs';
5
- import { getCookieConfig, init, requestUpload, requestUploadParts, completeMultipartUpload, confirmUpload, deleteFile, fetchProxyFile } from '../shared.mjs';
6
-
7
- // Helper to safely get cookies from Astro request
8
- function getCookie(request, name) {
9
- const cookieHeader = request.headers.get('cookie');
10
- if (!cookieHeader) return undefined;
11
- const cookies = cookieHeader.split(';').reduce((acc, cookie)=>{
12
- const [key, value] = cookie.trim().split('=');
13
- if (key && value) acc[key] = value;
14
- return acc;
15
- }, {});
16
- return cookies[name];
17
- }
18
- function createEdgeStoreAstroHandler(config) {
19
- const { provider = EdgeStoreProvider(), cookieConfig } = config;
20
- const log = new Logger(config.logLevel);
21
- globalThis._EDGE_STORE_LOGGER = log;
22
- log.debug('Creating EdgeStore Astro handler');
23
- const resolvedCookieConfig = getCookieConfig(cookieConfig);
24
- return async (context)=>{
25
- try {
26
- const { request } = context;
27
- const url = new URL(request.url);
28
- if (matchPath(url.pathname, 'health')) {
29
- return new Response('OK');
30
- } else if (matchPath(url.pathname, 'init')) {
31
- let ctx = {};
32
- try {
33
- ctx = 'createContext' in config ? await config.createContext(context) : {};
34
- } catch (err) {
35
- throw new EdgeStoreError({
36
- message: 'Error creating context',
37
- code: 'CREATE_CONTEXT_ERROR',
38
- cause: err instanceof Error ? err : undefined
39
- });
40
- }
41
- const { newCookies, ...body } = await init({
42
- ctx,
43
- provider,
44
- router: config.router,
45
- cookieConfig
46
- });
47
- const headers = new Headers();
48
- headers.set('Content-Type', 'application/json');
49
- // Set cookies
50
- if (Array.isArray(newCookies)) {
51
- for (const cookie of newCookies){
52
- headers.append('Set-Cookie', cookie);
53
- }
54
- } else if (newCookies) {
55
- headers.append('Set-Cookie', newCookies);
56
- }
57
- return new Response(JSON.stringify(body), {
58
- headers
59
- });
60
- } else if (matchPath(url.pathname, 'request-upload')) {
61
- const body = await request.json();
62
- const result = await requestUpload({
63
- provider,
64
- router: config.router,
65
- body,
66
- ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
67
- });
68
- return new Response(JSON.stringify(result), {
69
- headers: {
70
- 'Content-Type': 'application/json'
71
- }
72
- });
73
- } else if (matchPath(url.pathname, 'request-upload-parts')) {
74
- const body = await request.json();
75
- const result = await requestUploadParts({
76
- provider,
77
- router: config.router,
78
- body,
79
- ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
80
- });
81
- return new Response(JSON.stringify(result), {
82
- headers: {
83
- 'Content-Type': 'application/json'
84
- }
85
- });
86
- } else if (matchPath(url.pathname, 'complete-multipart-upload')) {
87
- const body = await request.json();
88
- await completeMultipartUpload({
89
- provider,
90
- router: config.router,
91
- body,
92
- ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
93
- });
94
- return new Response(null, {
95
- status: 200
96
- });
97
- } else if (matchPath(url.pathname, 'confirm-upload')) {
98
- const body = await request.json();
99
- const result = await confirmUpload({
100
- provider,
101
- router: config.router,
102
- body,
103
- ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
104
- });
105
- return new Response(JSON.stringify(result), {
106
- headers: {
107
- 'Content-Type': 'application/json'
108
- }
109
- });
110
- } else if (matchPath(url.pathname, 'delete-file')) {
111
- const body = await request.json();
112
- const result = await deleteFile({
113
- provider,
114
- router: config.router,
115
- body,
116
- ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
117
- });
118
- return new Response(JSON.stringify(result), {
119
- headers: {
120
- 'Content-Type': 'application/json'
121
- }
122
- });
123
- } else if (matchPath(url.pathname, 'proxy-file')) {
124
- const url = new URL(request.url).searchParams.get('url');
125
- if (typeof url === 'string') {
126
- const proxyRes = await fetchProxyFile({
127
- cookieHeader: request.headers.get('cookie') ?? undefined,
128
- url
129
- });
130
- const headers = new Headers();
131
- headers.set('Content-Type', proxyRes.contentType);
132
- return new Response(proxyRes.body, {
133
- headers,
134
- status: proxyRes.status
135
- });
136
- } else {
137
- return new Response(null, {
138
- status: 400
139
- });
140
- }
141
- } else {
142
- return new Response(null, {
143
- status: 404
144
- });
145
- }
146
- } catch (err) {
147
- if (err instanceof EdgeStoreError) {
148
- log[err.level](err.formattedMessage());
149
- if (err.cause) log[err.level](err.cause);
150
- return new Response(JSON.stringify(err.formattedJson()), {
151
- status: EDGE_STORE_ERROR_CODES[err.code],
152
- headers: {
153
- 'Content-Type': 'application/json'
154
- }
155
- });
156
- } else {
157
- log.error(err);
158
- return new Response(JSON.stringify(new EdgeStoreError({
159
- message: 'Internal Server Error',
160
- code: 'SERVER_ERROR'
161
- }).formattedJson()), {
162
- status: 500,
163
- headers: {
164
- 'Content-Type': 'application/json'
165
- }
166
- });
167
- }
168
- }
169
- };
170
- }
171
-
172
- export { createEdgeStoreAstroHandler };
@@ -1,108 +0,0 @@
1
- import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
2
- import Logger from '../../libs/logger.mjs';
3
- import { matchPath } from '../../libs/utils.mjs';
4
- import { EdgeStoreProvider } from '../../providers/edgestore/index.mjs';
5
- import { getCookieConfig, init, requestUpload, requestUploadParts, completeMultipartUpload, confirmUpload, deleteFile, fetchProxyFile } from '../shared.mjs';
6
-
7
- function createEdgeStoreExpressHandler(config) {
8
- const { provider = EdgeStoreProvider(), cookieConfig } = config;
9
- const log = new Logger(config.logLevel);
10
- globalThis._EDGE_STORE_LOGGER = log;
11
- log.debug('Creating EdgeStore Express handler');
12
- const resolvedCookieConfig = getCookieConfig(cookieConfig);
13
- return async (req, res)=>{
14
- try {
15
- const pathname = req.url ?? '';
16
- if (matchPath(pathname, '/health')) {
17
- res.send('OK');
18
- } else if (matchPath(pathname, '/init')) {
19
- let ctx = {};
20
- try {
21
- ctx = 'createContext' in config ? await config.createContext({
22
- req,
23
- res
24
- }) : {};
25
- } catch (err) {
26
- throw new EdgeStoreError({
27
- message: 'Error creating context',
28
- code: 'CREATE_CONTEXT_ERROR',
29
- cause: err instanceof Error ? err : undefined
30
- });
31
- }
32
- const { newCookies, ...body } = await init({
33
- ctx,
34
- provider,
35
- router: config.router,
36
- cookieConfig
37
- });
38
- res.setHeader('Set-Cookie', newCookies);
39
- res.json(body);
40
- } else if (matchPath(pathname, '/request-upload')) {
41
- res.json(await requestUpload({
42
- provider,
43
- router: config.router,
44
- body: req.body,
45
- ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
46
- }));
47
- } else if (matchPath(pathname, '/request-upload-parts')) {
48
- res.json(await requestUploadParts({
49
- provider,
50
- router: config.router,
51
- body: req.body,
52
- ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
53
- }));
54
- } else if (matchPath(pathname, '/complete-multipart-upload')) {
55
- await completeMultipartUpload({
56
- provider,
57
- router: config.router,
58
- body: req.body,
59
- ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
60
- });
61
- res.status(200).end();
62
- } else if (matchPath(pathname, '/confirm-upload')) {
63
- res.json(await confirmUpload({
64
- provider,
65
- router: config.router,
66
- body: req.body,
67
- ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
68
- }));
69
- } else if (matchPath(pathname, '/delete-file')) {
70
- res.json(await deleteFile({
71
- provider,
72
- router: config.router,
73
- body: req.body,
74
- ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
75
- }));
76
- } else if (matchPath(pathname, '/proxy-file')) {
77
- const { url } = req.query;
78
- if (typeof url === 'string') {
79
- const proxyRes = await fetchProxyFile({
80
- cookieHeader: req.headers.cookie,
81
- url
82
- });
83
- res.setHeader('Content-Type', proxyRes.contentType);
84
- res.status(proxyRes.status);
85
- res.end(proxyRes.body === null ? undefined : Buffer.from(proxyRes.body));
86
- } else {
87
- res.status(400).end();
88
- }
89
- } else {
90
- res.status(404).end();
91
- }
92
- } catch (err) {
93
- if (err instanceof EdgeStoreError) {
94
- log[err.level](err.formattedMessage());
95
- if (err.cause) log[err.level](err.cause);
96
- res.status(EDGE_STORE_ERROR_CODES[err.code]).json(err.formattedJson());
97
- } else {
98
- log.error(err);
99
- res.status(500).send(new EdgeStoreError({
100
- message: 'Internal Server Error',
101
- code: 'SERVER_ERROR'
102
- }).formattedJson());
103
- }
104
- }
105
- };
106
- }
107
-
108
- export { createEdgeStoreExpressHandler };
@@ -1,135 +0,0 @@
1
- import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
2
- import Logger from '../../libs/logger.mjs';
3
- import { matchPath } from '../../libs/utils.mjs';
4
- import { EdgeStoreProvider } from '../../providers/edgestore/index.mjs';
5
- import { getCookieConfig, init, requestUpload, requestUploadParts, completeMultipartUpload, confirmUpload, deleteFile, fetchProxyFile } from '../shared.mjs';
6
-
7
- // Helper to safely get cookies from Fastify request
8
- function getCookie(req, name) {
9
- // Check if cookies plugin is available
10
- if ('cookies' in req) {
11
- // Type assertion for TypeScript
12
- return req.cookies[name];
13
- }
14
- // Fallback to parsing cookie header
15
- const cookieHeader = req.headers.cookie;
16
- if (!cookieHeader) return undefined;
17
- const cookies = cookieHeader.split(';').reduce((acc, cookie)=>{
18
- const [key, value] = cookie.trim().split('=');
19
- if (key && value) acc[key] = value;
20
- return acc;
21
- }, {});
22
- return cookies[name];
23
- }
24
- function createEdgeStoreFastifyHandler(config) {
25
- const { provider = EdgeStoreProvider(), cookieConfig } = config;
26
- const log = new Logger(config.logLevel);
27
- globalThis._EDGE_STORE_LOGGER = log;
28
- log.debug('Creating EdgeStore Fastify handler');
29
- const resolvedCookieConfig = getCookieConfig(cookieConfig);
30
- return async (req, reply)=>{
31
- try {
32
- // Get the URL from the request - simplified approach
33
- const pathname = req.url;
34
- if (matchPath(pathname, '/health')) {
35
- return reply.send('OK');
36
- } else if (matchPath(pathname, '/init')) {
37
- let ctx = {};
38
- try {
39
- ctx = 'createContext' in config ? await config.createContext({
40
- req,
41
- reply
42
- }) : {};
43
- } catch (err) {
44
- throw new EdgeStoreError({
45
- message: 'Error creating context',
46
- code: 'CREATE_CONTEXT_ERROR',
47
- cause: err instanceof Error ? err : undefined
48
- });
49
- }
50
- const { newCookies, ...body } = await init({
51
- ctx,
52
- provider,
53
- router: config.router,
54
- cookieConfig
55
- });
56
- // Set cookies more efficiently - handling them using void operator
57
- // to explicitly mark these synchronous calls as intentionally not awaited
58
- if (Array.isArray(newCookies)) {
59
- // If it's an array of cookies, set them all
60
- for (const cookie of newCookies){
61
- void reply.header('Set-Cookie', cookie);
62
- }
63
- } else if (newCookies) {
64
- // If it's a single cookie string
65
- void reply.header('Set-Cookie', newCookies);
66
- }
67
- return reply.send(body);
68
- } else if (matchPath(pathname, '/request-upload')) {
69
- return reply.send(await requestUpload({
70
- provider,
71
- router: config.router,
72
- body: req.body,
73
- ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
74
- }));
75
- } else if (matchPath(pathname, '/request-upload-parts')) {
76
- return reply.send(await requestUploadParts({
77
- provider,
78
- router: config.router,
79
- body: req.body,
80
- ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
81
- }));
82
- } else if (matchPath(pathname, '/complete-multipart-upload')) {
83
- await completeMultipartUpload({
84
- provider,
85
- router: config.router,
86
- body: req.body,
87
- ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
88
- });
89
- return reply.status(200).send();
90
- } else if (matchPath(pathname, '/confirm-upload')) {
91
- return reply.send(await confirmUpload({
92
- provider,
93
- router: config.router,
94
- body: req.body,
95
- ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
96
- }));
97
- } else if (matchPath(pathname, '/delete-file')) {
98
- return reply.send(await deleteFile({
99
- provider,
100
- router: config.router,
101
- body: req.body,
102
- ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
103
- }));
104
- } else if (matchPath(pathname, '/proxy-file')) {
105
- const url = req.query ? req.query.url : undefined;
106
- if (typeof url === 'string') {
107
- const proxyRes = await fetchProxyFile({
108
- cookieHeader: req.headers.cookie,
109
- url
110
- });
111
- void reply.header('Content-Type', proxyRes.contentType);
112
- return reply.status(proxyRes.status).send(proxyRes.body === null ? undefined : Buffer.from(proxyRes.body));
113
- } else {
114
- return reply.status(400).send();
115
- }
116
- } else {
117
- return reply.status(404).send();
118
- }
119
- } catch (err) {
120
- if (err instanceof EdgeStoreError) {
121
- log[err.level](err.formattedMessage());
122
- if (err.cause) log[err.level](err.cause);
123
- return reply.status(EDGE_STORE_ERROR_CODES[err.code]).send(err.formattedJson());
124
- } else {
125
- log.error(err);
126
- return reply.status(500).send(new EdgeStoreError({
127
- message: 'Internal Server Error',
128
- code: 'SERVER_ERROR'
129
- }).formattedJson());
130
- }
131
- }
132
- };
133
- }
134
-
135
- export { createEdgeStoreFastifyHandler };
@@ -1,131 +0,0 @@
1
- import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
2
- import Logger from '../../libs/logger.mjs';
3
- import { matchPath } from '../../libs/utils.mjs';
4
- import { EdgeStoreProvider } from '../../providers/edgestore/index.mjs';
5
- import { getCookieConfig, init, requestUpload, requestUploadParts, completeMultipartUpload, confirmUpload, deleteFile, fetchProxyFile } from '../shared.mjs';
6
-
7
- // Helper to get a cookie value from Hono Context
8
- function getCookie(c, name) {
9
- const cookies = c.req.header('cookie');
10
- if (!cookies) return undefined;
11
- const match = new RegExp(`${name}=([^;]+)`).exec(cookies);
12
- return match ? match[1] : undefined;
13
- }
14
- function createEdgeStoreHonoHandler(config) {
15
- const { provider = EdgeStoreProvider(), cookieConfig } = config;
16
- const log = new Logger(config.logLevel);
17
- globalThis._EDGE_STORE_LOGGER = log;
18
- log.debug('Creating EdgeStore Hono handler');
19
- const resolvedCookieConfig = getCookieConfig(cookieConfig);
20
- return async (c)=>{
21
- try {
22
- const pathname = new URL(c.req.url).pathname;
23
- if (matchPath(pathname, '/health')) {
24
- return c.text('OK');
25
- } else if (matchPath(pathname, '/init')) {
26
- let ctx = {};
27
- try {
28
- ctx = 'createContext' in config ? await config.createContext({
29
- c
30
- }) : {};
31
- } catch (err) {
32
- throw new EdgeStoreError({
33
- message: 'Error creating context',
34
- code: 'CREATE_CONTEXT_ERROR',
35
- cause: err instanceof Error ? err : undefined
36
- });
37
- }
38
- const { newCookies, ...body } = await init({
39
- ctx,
40
- provider,
41
- router: config.router,
42
- cookieConfig
43
- });
44
- // Set cookies
45
- if (Array.isArray(newCookies)) {
46
- for (const cookie of newCookies){
47
- c.header('Set-Cookie', cookie, {
48
- append: true
49
- });
50
- }
51
- } else if (newCookies) {
52
- c.header('Set-Cookie', newCookies);
53
- }
54
- return c.json(body);
55
- } else if (matchPath(pathname, '/request-upload')) {
56
- const body = await c.req.json();
57
- return c.json(await requestUpload({
58
- provider,
59
- router: config.router,
60
- body,
61
- ctxToken: getCookie(c, resolvedCookieConfig.ctx.name)
62
- }));
63
- } else if (matchPath(pathname, '/request-upload-parts')) {
64
- const body = await c.req.json();
65
- return c.json(await requestUploadParts({
66
- provider,
67
- router: config.router,
68
- body,
69
- ctxToken: getCookie(c, resolvedCookieConfig.ctx.name)
70
- }));
71
- } else if (matchPath(pathname, '/complete-multipart-upload')) {
72
- const body = await c.req.json();
73
- await completeMultipartUpload({
74
- provider,
75
- router: config.router,
76
- body,
77
- ctxToken: getCookie(c, resolvedCookieConfig.ctx.name)
78
- });
79
- return c.body(null, 200);
80
- } else if (matchPath(pathname, '/confirm-upload')) {
81
- const body = await c.req.json();
82
- return c.json(await confirmUpload({
83
- provider,
84
- router: config.router,
85
- body,
86
- ctxToken: getCookie(c, resolvedCookieConfig.ctx.name)
87
- }));
88
- } else if (matchPath(pathname, '/delete-file')) {
89
- const body = await c.req.json();
90
- return c.json(await deleteFile({
91
- provider,
92
- router: config.router,
93
- body,
94
- ctxToken: getCookie(c, resolvedCookieConfig.ctx.name)
95
- }));
96
- } else if (matchPath(pathname, '/proxy-file')) {
97
- const url = c.req.query('url');
98
- if (typeof url === 'string') {
99
- const proxyRes = await fetchProxyFile({
100
- cookieHeader: c.req.header('cookie'),
101
- url
102
- });
103
- return new Response(proxyRes.body === null ? null : Buffer.from(proxyRes.body), {
104
- status: proxyRes.status,
105
- headers: {
106
- 'Content-Type': proxyRes.contentType
107
- }
108
- });
109
- } else {
110
- return c.body(null, 400);
111
- }
112
- } else {
113
- return c.body(null, 404);
114
- }
115
- } catch (err) {
116
- if (err instanceof EdgeStoreError) {
117
- log[err.level](err.formattedMessage());
118
- if (err.cause) log[err.level](err.cause);
119
- return c.json(err.formattedJson(), EDGE_STORE_ERROR_CODES[err.code]);
120
- } else {
121
- log.error(err);
122
- return c.json(new EdgeStoreError({
123
- message: 'Internal Server Error',
124
- code: 'SERVER_ERROR'
125
- }).formattedJson(), 500);
126
- }
127
- }
128
- };
129
- }
130
-
131
- export { createEdgeStoreHonoHandler };
@@ -1,12 +0,0 @@
1
- const IMAGE_MIME_TYPES = [
2
- 'image/jpeg',
3
- 'image/png',
4
- 'image/gif',
5
- 'image/webp',
6
- 'image/svg+xml',
7
- 'image/tiff',
8
- 'image/bmp',
9
- 'image/x-icon'
10
- ];
11
-
12
- export { IMAGE_MIME_TYPES };