-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from gagan-suie/dev
Fx: rearchitected app to remove excessive store usage
- Loading branch information
Showing
49 changed files
with
945 additions
and
938 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { error } from '@sveltejs/kit' | ||
import { env } from '$env/dynamic/public' | ||
|
||
const base = env.PUBLIC_API_URL | ||
|
||
async function send({ | ||
method, | ||
path, | ||
data, | ||
headers | ||
}: { | ||
method: string | ||
path: string | ||
data?: any | ||
headers?: any | ||
}) { | ||
const opts: any = { method, headers: {} } | ||
|
||
if (data) { | ||
opts.headers['Content-Type'] = 'application/json' | ||
opts.body = JSON.stringify(data) | ||
} | ||
|
||
// if headers sent manually | ||
if (headers && headers.userId) { | ||
opts.headers['userId'] = headers.userId | ||
} | ||
|
||
if (env.PUBLIC_CROSS_ORIGIN === 'false') { | ||
opts.headers['authorization'] = headers.token | ||
} else { | ||
opts.headers['x-api-key'] = env.PUBLIC_X_API_KEY | ||
} | ||
|
||
const res = await fetch(`${base}/${path}`, opts) | ||
if (res.ok || res.status === 422) { | ||
const text = await res.text() | ||
return text ? JSON.parse(text) : {} | ||
} | ||
|
||
return { error: res.status } | ||
} | ||
|
||
export function get(path: string, headers?: any) { | ||
return send({ method: 'GET', path, headers }) | ||
} | ||
|
||
export function del(path: string) { | ||
return send({ method: 'DELETE', path }) | ||
} | ||
|
||
export function post(path: string, data: any) { | ||
return send({ method: 'POST', path, data }) | ||
} | ||
|
||
export function put(path: string, data: any = {}) { | ||
return send({ method: 'PUT', path, data }) | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.