Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
e6906e3d
Commit
e6906e3d
authored
Jul 20, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
node-fetch wrapper
parent
0127bc42
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
19 deletions
+21
-19
fetch.ts
api/utils/fetch.ts
+18
-0
getDefaultHeaders.ts
pages/api-helpers/getDefaultHeaders.ts
+0
-7
getUrl.ts
pages/api-helpers/getUrl.ts
+0
-3
index.ts
pages/api/account/private-tags/address/index.ts
+3
-9
No files found.
api/utils/fetch.ts
0 → 100644
View file @
e6906e3d
import
type
{
RequestInit
,
Response
}
from
'
node-fetch
'
;
import
nodeFetch
from
'
node-fetch
'
;
// first arg can be only a string
// FIXME migrate to RequestInfo later
export
default
function
fetch
(
path
:
string
,
init
?:
RequestInit
):
Promise
<
Response
>
{
const
headers
=
{
accept
:
'
application/json
'
,
authorization
:
`Bearer
${
process
.
env
.
API_AUTHORIZATION_TOKEN
}
`
,
'
content-type
'
:
'
application/json
'
,
}
const
url
=
`https://
${
process
.
env
.
API_HOST
}${
process
.
env
.
API_BASE_PATH
}${
path
}
`
;
return
nodeFetch
(
url
,
{
headers
,
...
init
,
})
}
pages/api-helpers/getDefaultHeaders.ts
deleted
100644 → 0
View file @
0127bc42
export
default
function
getDefaultHeaders
()
{
return
{
accept
:
'
application/json
'
,
authorization
:
`Bearer
${
process
.
env
.
API_AUTHORIZATION_TOKEN
}
`
,
'
content-type
'
:
'
application/json
'
,
}
}
pages/api-helpers/getUrl.ts
deleted
100644 → 0
View file @
0127bc42
export
default
function
getUrl
(
path
:
string
)
{
return
`https://
${
process
.
env
.
API_HOST
}${
process
.
env
.
API_BASE_PATH
}${
path
}
`
}
pages/api/account/private-tags/address/index.ts
View file @
e6906e3d
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
import
fetch
from
'
node-fetch
'
;
import
getDefaultHeaders
from
'
pages/api-helpers/getDefaultHeaders
'
;
import
getUrl
from
'
pages/api-helpers/getUrl
'
;
import
fetch
from
'
api/utils/fetch
'
;
export
default
async
function
handler
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
const
url
=
getUrl
(
'
/account/v1/user/tags/address
'
)
;
const
url
=
'
/account/v1/user/tags/address
'
;
switch
(
_req
.
method
)
{
case
'
GET
'
:
{
const
response
=
await
fetch
(
url
,
{
method
:
'
GET
'
,
headers
:
getDefaultHeaders
(),
})
const
response
=
await
fetch
(
url
)
const
data
=
await
response
.
json
();
res
.
status
(
200
).
json
(
data
)
...
...
@@ -22,7 +17,6 @@ export default async function handler(_req: NextApiRequest, res: NextApiResponse
case
'
POST
'
:
{
const
response
=
await
fetch
(
url
,
{
method
:
'
POST
'
,
headers
:
getDefaultHeaders
(),
body
:
_req
.
body
,
})
const
data
=
await
response
.
json
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment