@hashrytech/quick-components-kit 0.14.2 → 0.14.3
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/CHANGELOG.md +6 -0
- package/dist/modules/api-proxy.d.ts +4 -0
- package/dist/modules/api-proxy.js +7 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,8 @@ import type { RequestHandler } from '@sveltejs/kit';
|
|
|
5
5
|
export interface RestApiProxyConfig {
|
|
6
6
|
/** Your API HOST URL (e.g. 'https://api.example.com') */
|
|
7
7
|
host: string;
|
|
8
|
+
/** Optional flag to append a trailing slash to the path */
|
|
9
|
+
appendSlash?: boolean;
|
|
8
10
|
/** Optional array of allowed path prefixes to restrict access to downstream paths. Example: v1/products */
|
|
9
11
|
allowedPaths?: string[];
|
|
10
12
|
/** Optional extra headers to forward from the request */
|
|
@@ -13,6 +15,8 @@ export interface RestApiProxyConfig {
|
|
|
13
15
|
safeResponseHeaders?: string[];
|
|
14
16
|
/** Optional function to extract token from session */
|
|
15
17
|
extractToken?: (locals: App.Locals) => string | undefined;
|
|
18
|
+
/** Optional flag to enable debug logging */
|
|
19
|
+
debug?: boolean;
|
|
16
20
|
}
|
|
17
21
|
export declare const defaultRequestHeaders: string[];
|
|
18
22
|
export declare const defaultResponseHeaders: string[];
|
|
@@ -5,16 +5,21 @@ export const defaultResponseHeaders = ['content-type', 'content-length', 'cache-
|
|
|
5
5
|
* Creates a set of SvelteKit request handlers for proxying API calls securely.
|
|
6
6
|
*/
|
|
7
7
|
export function createProxyHandlers(config) {
|
|
8
|
+
if (config.debug)
|
|
9
|
+
console.debug("Creating proxy handlers with config:", config);
|
|
8
10
|
async function handler(event) {
|
|
9
11
|
const path = event.params.path;
|
|
10
12
|
const queryString = event.url.searchParams.toString();
|
|
11
|
-
const
|
|
13
|
+
const slash = config.appendSlash ? '/' : '';
|
|
14
|
+
const fullPath = `/${path}${slash}${queryString ? `?${queryString}` : ''}`;
|
|
12
15
|
const url = `${config.host}${fullPath}`;
|
|
16
|
+
if (config.debug)
|
|
17
|
+
console.debug(`Proxying request to: ${url}`);
|
|
13
18
|
// Validate the path against allowed prefixes if specified
|
|
14
19
|
if (config.allowedPaths && config.allowedPaths.length > 0) {
|
|
15
20
|
const isAllowed = config.allowedPaths.some((prefix) => path?.startsWith(prefix));
|
|
16
21
|
if (!isAllowed)
|
|
17
|
-
throw error(403, 'Forbidden: This API path is not allowed.');
|
|
22
|
+
throw error(403, 'Forbidden: This proxy API path is not allowed.');
|
|
18
23
|
}
|
|
19
24
|
let headers = new Headers(event.request.headers);
|
|
20
25
|
if (config.safeRequestHeaders && config.safeRequestHeaders.length > 0) {
|