Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nextjs skeleton for the ui #11

Merged
merged 24 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,35 @@
*.pem
*config.yaml

.DS_Store
.DS_Store

# dependencies
ui/node_modules
ui/.pnp
ui/*.pnp.js
ui/*.yarn/install-state.gz

# testing
ui/coverage

# next.js
ui/.next/
ui/out/

# production
ui/build

# debug
ui/npm-debug.log*
ui/yarn-debug.log*
ui/yarn-error.log*

# local env files
ui/.env*.local

# vercel
ui/.vercel

# typescript
ui/*.tsbuildinfo
ui/next-env.d.ts
7 changes: 7 additions & 0 deletions internal/api/handlers.go
kayra1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ func NewGoCertRouter(env *Environment) http.Handler {
router.HandleFunc("POST /certificate_requests/{id}/certificate/reject", RejectCertificate(env))
router.HandleFunc("DELETE /certificate_requests/{id}/certificate", DeleteCertificate(env))

frontend := newFrontendFileServer(env.FrontendDir)

v1 := http.NewServeMux()
v1.HandleFunc("GET /status", HealthCheck)
v1.Handle("/api/v1/", http.StripPrefix("/api/v1", router))
v1.Handle("/", frontend)

return logging(v1)
}

func newFrontendFileServer(dir string) http.Handler {
return http.FileServer(http.Dir(dir))
}

// the health check endpoint simply returns a http.StatusOK
func HealthCheck(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) //nolint:errcheck
Expand Down
26 changes: 17 additions & 9 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ import (
)

type ConfigYAML struct {
KeyPath string
CertPath string
DBPath string
Port int
KeyPath string
CertPath string
DBPath string
FrontendDir string
Port int
}

type Config struct {
Key []byte
Cert []byte
DBPath string
Port int
Key []byte
Cert []byte
DBPath string
FrontendDir string
Port int
}

type Environment struct {
DB *certdb.CertificateRequestsRepository
DB *certdb.CertificateRequestsRepository
FrontendDir string
}

// validateConfigFile opens and processes the given yaml file, and catches errors in the process
Expand All @@ -56,6 +59,9 @@ func validateConfigFile(filePath string) (Config, error) {
if err != nil {
return config, errors.Join(validationErr, err)
}
if c.FrontendDir == "" {
c.FrontendDir = "ui/out"
}
err = dbfile.Close()
if err != nil {
return config, errors.Join(validationErr, err)
Expand All @@ -65,6 +71,7 @@ func validateConfigFile(filePath string) (Config, error) {
config.Key = key
config.DBPath = c.DBPath
config.Port = c.Port
config.FrontendDir = c.FrontendDir
return config, nil
}

Expand All @@ -85,6 +92,7 @@ func NewServer(configFile string) (*http.Server, error) {

env := &Environment{}
env.DB = db
env.FrontendDir = config.FrontendDir
router := NewGoCertRouter(env)

s := &http.Server{
Expand Down
3 changes: 3 additions & 0 deletions ui/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions ui/README.md
kayra1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
kayra1 marked this conversation as resolved.
Show resolved Hide resolved
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
kayra1 marked this conversation as resolved.
Show resolved Hide resolved

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
kayra1 marked this conversation as resolved.
Show resolved Hide resolved
Binary file added ui/bun.lockb
kayra1 marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
6 changes: 6 additions & 0 deletions ui/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "export"
};

export default nextConfig;
24 changes: 24 additions & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "gocert",
"version": "0.1.0",
gruyaume marked this conversation as resolved.
Show resolved Hide resolved
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"react": "^18",
"react-dom": "^18",
"next": "14.2.3"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.3"
}
}
1 change: 1 addition & 0 deletions ui/public/next.svg
kayra1 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ui/public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui/src/app/favicon.ico
Binary file not shown.
107 changes: 107 additions & 0 deletions ui/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
:root {
--max-width: 1100px;
--border-radius: 12px;
--font-mono: ui-monospace, Menlo, Monaco, "Cascadia Mono", "Segoe UI Mono",
"Roboto Mono", "Oxygen Mono", "Ubuntu Monospace", "Source Code Pro",
"Fira Mono", "Droid Sans Mono", "Courier New", monospace;

--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;

--primary-glow: conic-gradient(
from 180deg at 50% 50%,
#16abff33 0deg,
#0885ff33 55deg,
#54d6ff33 120deg,
#0071ff33 160deg,
transparent 360deg
);
--secondary-glow: radial-gradient(
rgba(255, 255, 255, 1),
rgba(255, 255, 255, 0)
);

--tile-start-rgb: 239, 245, 249;
--tile-end-rgb: 228, 232, 233;
--tile-border: conic-gradient(
#00000080,
#00000040,
#00000030,
#00000020,
#00000010,
#00000010,
#00000080
);

--callout-rgb: 238, 240, 241;
--callout-border-rgb: 172, 175, 176;
--card-rgb: 180, 185, 188;
--card-border-rgb: 131, 134, 135;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;

--primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0));
--secondary-glow: linear-gradient(
to bottom right,
rgba(1, 65, 255, 0),
rgba(1, 65, 255, 0),
rgba(1, 65, 255, 0.3)
);

--tile-start-rgb: 2, 13, 46;
--tile-end-rgb: 2, 5, 19;
--tile-border: conic-gradient(
#ffffff80,
#ffffff40,
#ffffff30,
#ffffff20,
#ffffff10,
#ffffff10,
#ffffff80
);

--callout-rgb: 20, 20, 20;
--callout-border-rgb: 108, 108, 108;
--card-rgb: 100, 100, 100;
--card-border-rgb: 200, 200, 200;
}
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}

a {
color: inherit;
text-decoration: none;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
}
22 changes: 22 additions & 0 deletions ui/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
}
Loading
Loading