Skip to content

Commit 86aa4eb

Browse files
committed
rafactor: fetch, storage helper
1 parent b868201 commit 86aa4eb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

nuxt/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { $Fetch } from 'nitropack/types';
55

66
declare module '#app' {
77
interface NuxtApp {
8-
$storage(msg: string): string;
98
$http<T = unknown>(
109
request: NitroFetchRequest,
1110
opts?: HttpFetchOptions

nuxt/utils/helpers.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { NitroFetchRequest } from 'nitropack/types';
2+
import type { HttpFetchOptions } from '~';
3+
4+
export function $http<T = unknown>(request: NitroFetchRequest, opts?: HttpFetchOptions): Promise<T> {
5+
const { $http: http } = useNuxtApp();
6+
7+
return http(request, opts);
8+
}
9+
10+
export function $storage(path: string): string {
11+
if (!path) return '';
12+
13+
const config = useRuntimeConfig();
14+
15+
return path.startsWith('http://') || path.startsWith('https://')
16+
? path
17+
: config.public.storageBase + path;
18+
}

0 commit comments

Comments
 (0)