Added compile time attributes to config class
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Dominic Grimm 2022-02-04 17:01:15 +01:00
parent 12a0eee216
commit 87f6f48b32
4 changed files with 23 additions and 6 deletions

View file

@ -7,8 +7,6 @@ POSTGRES_PASSWORD=
# Backend
BACKEND_URL=URL
BACKEND_ADMIN_EMAIL=
BACKEND_ADMIN_PASSWORD=
# Backend - API
BACKEND_API_GRAPHQL_PLAYGROUND=false
BACKEND_JWT_SECRET=

View file

@ -11,7 +11,7 @@ module Backend
def draw_routes : Nil
# enable graphql playground when in development mode or explicitly enabled
if Backend.config.api.graphql_playground || {{ flag?(:development) }}
if Backend.config.api.graphql_playground_fully_enabled
Log.info { "GraphQL playground enabled" }
get "/" do |context|

View file

@ -13,6 +13,23 @@ module Backend
class Config
include EnvConfig
enum BuildEnv
Development
Production
end
def development : Bool
{{ flag?(:development) }}
end
def production : Bool
!development
end
def build_env : BuildEnv
development ? BuildEnv::Development : BuildEnv::Production
end
getter url : String
@[EnvConfig::Setting(key: "api")]
@ -32,6 +49,10 @@ module Backend
getter graphql_playground : Bool
getter jwt_secret : String
def graphql_playground_fully_enabled : Bool
Backend.config.development || graphql_playground
end
end
class WorkerConfig

View file

@ -5,8 +5,6 @@ import Router from "next/router";
import * as cookieNames from "../lib/cookieNames";
function Navbar(): JSX.Element {
const isLoggedIn = !!Cookies.get(cookieNames.TOKEN);
function handleLogout(event: Event): void {
event.preventDefault();
Cookies.remove(cookieNames.TOKEN);
@ -17,7 +15,7 @@ function Navbar(): JSX.Element {
<nav>
<ul>
<li>
{isLoggedIn ? (
{!!Cookies.get(cookieNames.TOKEN) ? (
<button onClick={handleLogout as any}>Logout</button>
) : (
<Link href="/login" passHref>