-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
NODE_ENV=development | ||
|
||
# Development | ||
NEXT_PUBLIC_SITE_URL=http://localhost:3000 | ||
|
||
# Database | ||
DB_USERNAME=yourusername | ||
DB_PASSWORD=yourpassword | ||
DB_HOST=cockroachdb_cluster | ||
DB_PORT=26257 | ||
DB_NAME=panther_dev | ||
DB_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=verify-full |
This file was deleted.
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,26 @@ | ||
import getURL from '@/utils/getURL'; | ||
|
||
async function getData(): Promise<{ status: string }> { | ||
const res = await fetch(getURL('/api/health')); | ||
// The return value is *not* serialized | ||
// You can return Date, Map, Set, etc. | ||
|
||
if (!res.ok) { | ||
// This will activate the closest `error.js` Error Boundary | ||
throw new Error('Failed to fetch data'); | ||
} | ||
|
||
const data = await res.json(); | ||
|
||
return data as { status: string }; | ||
} | ||
|
||
export default async function HealthPage(): Promise<JSX.Element> { | ||
const data = await getData(); | ||
return ( | ||
<div className="flex min-h-screen flex-col items-center justify-between p-24 dark:bg-black dark:text-slate-50 transition-colors duration-150"> | ||
<h1>Health</h1> | ||
<p data-testid="health-status">{data.status}</p> | ||
</div> | ||
); | ||
} |
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,17 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
export async function GET(): Promise<NextResponse> { | ||
try { | ||
const userCount = await prisma.user.count(); | ||
if (userCount <= 0) { | ||
throw new Error('No users found, seed failed'); | ||
} | ||
|
||
return NextResponse.json({ status: 'healthy' }); | ||
} catch (error) { | ||
return NextResponse.json({ status: 'error', error }); | ||
} | ||
} |
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 @@ | ||
const IS_SERVER = typeof window === 'undefined'; | ||
export default function getURL(path: string): string { | ||
const baseURL = IS_SERVER | ||
? process.env.NEXT_PUBLIC_SITE_URL | ||
: window.location.origin; | ||
|
||
return new URL(path, baseURL).toString(); | ||
} |
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 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('should navigate to health page and be healthy', async ({ page }) => { | ||
await page.goto('/health'); | ||
await expect(page).toHaveURL('/health'); | ||
const p = page.getByTestId('health-status'); | ||
await expect(p).toHaveText('healthy'); | ||
}); |
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