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
156cde08
Commit
156cde08
authored
Sep 05, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sentry to api routes
parent
8e6a3dde
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
23 deletions
+38
-23
.env.example
.env.example
+1
-0
handler.ts
lib/api/handler.ts
+29
-22
next.config.js
next.config.js
+8
-1
No files found.
.env.example
View file @
156cde08
...
...
@@ -4,6 +4,7 @@ NEXT_PUBLIC_SENTRY_DSN=xxx
SENTRY_ORG=block-scout
SENTRY_PROJECT=new-ui
SENTRY_AUTH_TOKEN=xxx
SENTRY_IGNORE_API_RESOLUTION_ERROR=1
NEXT_PUBLIC_BLOCKSCOUT_VERSION=xxx
NEXT_PUBLIC_FOOTER_GITHUB_LINK=https://github.com/blockscout/blockscout
NEXT_PUBLIC_FOOTER_TWITTER_LINK=https://www.twitter.com/blockscoutcom
...
...
lib/api/handler.ts
View file @
156cde08
import
{
withSentry
}
from
'
@sentry/nextjs
'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'
next
'
;
import
fetch
from
'
lib/api/fetch
'
;
...
...
@@ -5,33 +6,39 @@ import getUrlWithNetwork from 'lib/api/getUrlWithNetwork';
type
Methods
=
'
GET
'
|
'
POST
'
|
'
PUT
'
|
'
DELETE
'
;
export
default
function
handler
(
getUrl
:
(
_req
:
NextApiRequest
)
=>
string
,
allowedMethods
:
Array
<
Methods
>
)
{
return
async
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
)
=>
{
if
(
_req
.
method
&&
allowedMethods
.
includes
(
_req
.
method
as
Methods
))
{
const
isBodyDisallowed
=
_req
.
method
===
'
GET
'
||
_req
.
method
===
'
HEAD
'
;
const
url
=
getUrlWithNetwork
(
_req
,
`/api
${
getUrl
(
_req
)
}
`
);
const
response
=
await
fetch
(
url
,
{
method
:
_req
.
method
,
body
:
isBodyDisallowed
?
undefined
:
_req
.
body
,
});
export
default
function
createHandler
(
getUrl
:
(
_req
:
NextApiRequest
)
=>
string
,
allowedMethods
:
Array
<
Methods
>
)
{
const
handler
=
async
(
_req
:
NextApiRequest
,
res
:
NextApiResponse
)
=>
{
if
(
!
_req
.
method
||
!
allowedMethods
.
includes
(
_req
.
method
as
Methods
))
{
res
.
setHeader
(
'
Allow
'
,
allowedMethods
);
res
.
status
(
405
).
end
(
`Method
${
_req
.
method
}
Not Allowed`
);
return
;
}
if
(
response
.
status
!==
200
)
{
try
{
const
error
=
await
response
.
json
()
as
{
errors
:
unknown
};
res
.
status
(
500
).
json
(
error
?.
errors
||
{});
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
statusText
:
response
.
statusText
,
status
:
response
.
status
});
}
const
isBodyDisallowed
=
_req
.
method
===
'
GET
'
||
_req
.
method
===
'
HEAD
'
;
return
;
}
const
url
=
getUrlWithNetwork
(
_req
,
`/api
${
getUrl
(
_req
)
}
`
);
const
response
=
await
fetch
(
url
,
{
method
:
_req
.
method
,
body
:
isBodyDisallowed
?
undefined
:
_req
.
body
,
});
if
(
response
.
status
===
200
)
{
const
data
=
await
response
.
json
();
res
.
status
(
200
).
json
(
data
);
}
else
{
res
.
setHeader
(
'
Allow
'
,
allowedMethods
);
res
.
status
(
405
).
end
(
`Method
${
_req
.
method
}
Not Allowed`
);
return
;
}
let
responseError
;
try
{
const
error
=
await
response
.
json
()
as
{
errors
:
unknown
};
responseError
=
error
?.
errors
||
{};
}
catch
(
error
)
{
responseError
=
{
statusText
:
response
.
statusText
,
status
:
response
.
status
};
}
res
.
status
(
500
).
json
(
responseError
);
};
return
withSentry
(
handler
);
}
next.config.js
View file @
156cde08
...
...
@@ -5,7 +5,14 @@ const path = require('path');
const
moduleExports
=
{
include
:
path
.
resolve
(
__dirname
,
'
icons
'
),
reactStrictMode
:
true
,
webpack
(
config
)
{
webpack
(
config
,
{
webpack
})
{
config
.
plugins
.
push
(
new
webpack
.
DefinePlugin
({
__SENTRY_DEBUG__
:
false
,
__SENTRY_TRACING__
:
false
,
}),
);
return
config
;
},
async
redirects
()
{
...
...
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