Skip to content

Commit

Permalink
Merge pull request #63 from nipreps/rf/endpoint
Browse files Browse the repository at this point in the history
RF: Server endpoints
  • Loading branch information
mgxd authored Dec 15, 2022
2 parents 9ad439d + fa25fb4 commit f9adcf4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
11 changes: 9 additions & 2 deletions migas_server/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

from pkg_resources import resource_filename
from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware
from strawberry.fastapi import GraphQLRouter

Expand Down Expand Up @@ -57,10 +59,15 @@ async def shutdown():
await app.requests.close()


@app.get("/")
async def root():
@app.get("/info")
async def info():
return {
"package": "migas",
"version": __version__,
"message": "Visit /graphql for GraphiQL interface",
}

@app.get("/")
async def home():
index = resource_filename("migas_server", "frontend/index.html")
return FileResponse(index)
11 changes: 11 additions & 0 deletions migas_server/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="eng">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Migas Telemetry</title>
</head>
<body>
<p>Migas collects anonymized usage information across projects.</p>
</body>
</html>
8 changes: 7 additions & 1 deletion migas_server/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ def client(event_loop: asyncio.BaseEventLoop) -> Iterator[TestClient]:
yield c


def test_server_startup_shutdown(client: TestClient) -> None:
def test_server_landing(client: TestClient) -> None:
res = client.get("/")
assert res.status_code == 200
assert 'html' in res.headers.get("Content-Type")


def test_server_info(client: TestClient) -> None:
res = client.get("/info")
assert res.status_code == 200
assert res.json()["package"] == "migas"


Expand Down

0 comments on commit f9adcf4

Please sign in to comment.