-
Notifications
You must be signed in to change notification settings - Fork 1
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 #18 from UoA-eResearch/IDS-966-submit-changes-to-b…
…ackend IDS-966 submit project information changes to backend
- Loading branch information
Showing
28 changed files
with
910 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ __pycache__ | |
api_keys.json | ||
.vscode/* | ||
.coverage | ||
|
||
# Ignored local configuration files to keep secrets safe. | ||
*.local |
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,2 @@ | ||
VITE_API_BASE_URL=http://localhost:8000 | ||
CORS_ALLOW_HOST='["http://localhost:5173"]' |
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 @@ | ||
CORS_ALLOW_HOST='["https://uoa-eresearch.github.io/driveoff/"]' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 @@ | ||
# API server for offboarding | ||
|
||
## Setting a mode | ||
By default, the API server runs in development mode. To change to production mode and use production env variables (e.g. API keys, etc), set `MODE=production`. e.g.: | ||
|
||
``` | ||
MODE=production fastapi run src/api/main.py | ||
``` |
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,21 @@ | ||
"""Module for CORS-related functionality.""" | ||
|
||
from fastapi import FastAPI | ||
from fastapi.middleware.cors import CORSMiddleware | ||
|
||
from config import get_settings | ||
|
||
|
||
def add_cors_middleware(app: FastAPI) -> None: | ||
"""Adds CORS middleware to the server app. | ||
Args: | ||
app (FastAPI): The FastAPI app to add middleware to. | ||
""" | ||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=get_settings().cors_allow_host, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) |
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,41 @@ | ||
"""Module for reading configuration files.""" | ||
|
||
import os | ||
from functools import lru_cache | ||
from pathlib import Path | ||
|
||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
|
||
def get_env_file() -> list[Path]: | ||
"""Given the mode this app should run in, return the dotenv files | ||
that should be used. If no file matching mode exists, raises a ValueError. | ||
Returns: | ||
list[Path]: The list of dotenv files. | ||
""" | ||
mode = "development" | ||
if "MODE" in os.environ: | ||
mode = os.environ["MODE"] | ||
mode_dir = Path("modes") | ||
all_env_files = [mode_dir / f".env.{mode}", mode_dir / f".env.{mode}.local"] | ||
files_that_exist = [file for file in all_env_files if file.is_file()] | ||
if len(files_that_exist) == 0: | ||
raise ValueError("No matching dotenv file exists for specified mode.") | ||
return files_that_exist | ||
|
||
|
||
class Settings(BaseSettings): | ||
""" | ||
Configurations for Driveoff. Use get_settings() for a cached version of the settings. | ||
""" | ||
|
||
cors_allow_host: list[str] = [] | ||
|
||
model_config = SettingsConfigDict(env_file=get_env_file(), extra="ignore") | ||
|
||
|
||
@lru_cache | ||
def get_settings() -> Settings: | ||
"""Returns a cached version of the Settings.""" | ||
return Settings() |
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 |
---|---|---|
|
@@ -12,7 +12,6 @@ node_modules | |
dist | ||
dist-ssr | ||
coverage | ||
*.local | ||
|
||
/cypress/videos/ | ||
/cypress/screenshots/ | ||
|
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,7 @@ | ||
import { defineConfig } from '@hey-api/openapi-ts'; | ||
|
||
export default defineConfig({ | ||
client: '@hey-api/client-fetch', | ||
input: 'http://localhost:8000/openapi.json', | ||
output: 'src/client', | ||
}); |
Oops, something went wrong.