Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nomad-FAIR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nomad-lab
nomad-FAIR
Commits
bac3146d
Commit
bac3146d
authored
4 years ago
by
Markus Scheidgen
Browse files
Options
Downloads
Patches
Plain Diff
Added a more friendly default 404 response for the nomad app.
parent
fd8e62d2
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!283
Merge v0.10.0 into master for release
,
!277
Added a more friendly default 404 response for the nomad app.
Pipeline
#95568
passed
4 years ago
Stage: build
Stage: test
Stage: release
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
nomad/app/main.py
+57
-0
57 additions, 0 deletions
nomad/app/main.py
with
58 additions
and
0 deletions
.gitignore
+
1
−
0
View file @
bac3146d
...
...
@@ -34,3 +34,4 @@ parser.osio.log
gui/src/metainfo.json
gui/src/searchQuantities.json
examples/workdir/
*/node_modules/
This diff is collapsed.
Click to expand it.
nomad/app/main.py
+
57
−
0
View file @
bac3146d
...
...
@@ -17,8 +17,11 @@
#
from
fastapi
import
FastAPI
,
status
,
Response
from
fastapi.responses
import
JSONResponse
,
HTMLResponse
from
fastapi.middleware.wsgi
import
WSGIMiddleware
from
starlette.middleware.base
import
BaseHTTPMiddleware
from
starlette.exceptions
import
HTTPException
as
StarletteHTTPException
from
fastapi.exception_handlers
import
http_exception_handler
as
default_http_exception_handler
from
nomad
import
config
,
infrastructure
...
...
@@ -70,3 +73,57 @@ async def startup_event():
pass
infrastructure
.
setup
()
@app.exception_handler
(
StarletteHTTPException
)
async
def
http_exception_handler
(
request
,
exc
):
if
exc
.
status_code
!=
404
:
return
await
default_http_exception_handler
(
request
,
exc
)
try
:
accept
=
request
.
headers
[
'
accept
'
]
except
Exception
:
accept
=
None
if
accept
is
not
None
and
'
html
'
in
accept
:
return
HTMLResponse
(
status_code
=
404
,
content
=
f
'''
<html>
<head><title>
{
config
.
meta
.
name
}
</title></head>
<body>
<h1>NOMAD app</h1>
<h2>info</h2>
{
'
<br/>
'
.
join
(
f
'
{
key
}:
{
value
}
'
for key, value in config.meta.items())
}
<h2>apis</h2>
<a href=
"
{
app_base
}
/api
"
>NOMAD API v0</a><br/>
<a href=
"
{
app_base
}
/api/v1/extensions/docs
"
>NOMAD API v1</a><br/>
<a href=
"
{
app_base
}
/optimade/v1/extensions/docs
"
>Optimade API</a><br/>
<a href=
"
{
app_base
}
/dcat
"
>DCAT API</a><br/>
</body>
</html>
'''
)
return
JSONResponse
(
status_code
=
404
,
content
=
{
'
detail
'
:
'
Not found
'
,
'
info
'
:
{
'
app
'
:
config
.
meta
,
'
apis
'
:
{
'
v0
'
:
{
'
root
'
:
f
'
{
app_base
}
/api
'
,
'
dashboard
'
:
f
'
{
app_base
}
/api
'
,
},
'
v1
'
:
{
'
root
'
:
f
'
{
app_base
}
/api/v1
'
,
'
dashboard
'
:
f
'
{
app_base
}
/api/v1/extensions/docs
'
,
'
documentation
'
:
f
'
{
app_base
}
/api/v1/extensions/redoc
'
,
},
'
optimade
'
:
{
'
root
'
:
f
'
{
app_base
}
/optimade/v1
'
,
'
dashboard
'
:
f
'
{
app_base
}
/optimade/v1/extensions/docs
'
},
'
dcat
'
:
{
'
root
'
:
f
'
{
app_base
}
/dcat
'
,
'
dashboard
'
:
f
'
{
app_base
}
/dcat
'
}
}
}
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment