bootstrapped

This commit is contained in:
Milo Schwartz 2024-09-27 21:39:03 -04:00
parent b7c1716fa7
commit d2e35b4a1f
No known key found for this signature in database
24 changed files with 15511 additions and 5203 deletions

View file

@ -1,3 +1,3 @@
{ {
"extends": ["next/core-web-vitals", "next/typescript"] "extends": ["next/core-web-vitals", "next/typescript"]
} }

27
.gitignore vendored
View file

@ -1,36 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules /node_modules
/.pnp /.pnp
.pnp.js .pnp.js
.yarn/install-state.gz .yarn/install-state.gz
# testing
/coverage /coverage
# next.js
/.next/ /.next/
/out/ /out/
# production
/build /build
# misc
.DS_Store .DS_Store
*.pem *.pem
# debug
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
# local env files
.env*.local .env*.local
.env
# vercel
.vercel .vercel
# typescript
*.tsbuildinfo *.tsbuildinfo
next-env.d.ts next-env.d.ts
*.db
*.sqlite
*.sqlite3
package-lock.json
*.log
.machinelogs*.json
*-audit.json

4
.prettierrc Normal file
View file

@ -0,0 +1,4 @@
{
"tabWidth": 4,
"printWidth": 80
}

View file

@ -1,36 +1 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). Main App and API server for Fossorial
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
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.
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## 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/app/building-your-application/deploying) for more details.

0
config/.gitkeep Normal file
View file

0
config/db/.gitkeep Normal file
View file

0
config/logs/.gitkeep Normal file
View file

12
drizzle.config.ts Normal file
View file

@ -0,0 +1,12 @@
import { defineConfig } from "drizzle-kit";
import enviroment from "@server/environment"
export default defineConfig({
dialect: "sqlite",
schema: "server/db/schema.ts",
out: "server/migrations",
verbose: true,
dbCredentials: {
url: `${enviroment.CONFIG_PATH}/db/db.sqlite`
},
});

20162
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,26 +1,43 @@
{ {
"name": "pangolin", "name": "@fossorial/pangolin",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "dev": "dotenvx run -- tsx watch server/index.ts",
"build": "next build", "db:generate": "drizzle-kit generate",
"start": "next start", "db:push": "drizzle-kit push",
"lint": "next lint" "db:studio": "drizzle-kit studio"
}, },
"dependencies": { "dependencies": {
"react": "^18", "axios": "1.7.7",
"react-dom": "^18", "better-sqlite3": "11.3.0",
"next": "14.2.13" "cors": "2.8.5",
}, "drizzle-orm": "0.33.0",
"devDependencies": { "expo-sqlite": "14.0.6",
"typescript": "^5", "express": "4.21.0",
"@types/node": "^20", "helmet": "7.1.0",
"@types/react": "^18", "next": "14.2.13",
"@types/react-dom": "^18", "react": "^18",
"postcss": "^8", "react-dom": "^18",
"tailwindcss": "^3.4.1", "winston": "3.14.2",
"eslint": "^8", "winston-daily-rotate-file": "5.0.0",
"eslint-config-next": "14.2.13" "zod": "3.23.8",
} "zod-validation-error": "3.4.0"
},
"devDependencies": {
"@dotenvx/dotenvx": "1.14.2",
"@types/better-sqlite3": "7.6.11",
"@types/cors": "2.8.17",
"@types/express": "5.0.0",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"drizzle-kit": "0.24.2",
"eslint": "^8",
"eslint-config-next": "14.2.13",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"tsx": "4.19.1",
"typescript": "^5"
}
} }

View file

@ -1,8 +1,8 @@
/** @type {import('postcss-load-config').Config} */ /** @type {import('postcss-load-config').Config} */
const config = { const config = {
plugins: { plugins: {
tailwindcss: {}, tailwindcss: {},
}, },
}; };
export default config; export default config;

9
server/db/index.ts Normal file
View file

@ -0,0 +1,9 @@
import { drizzle } from "drizzle-orm/better-sqlite3";
import Database from "better-sqlite3";
import * as schema from "./schema";
import environment from "@server/environment";
const sqlite = new Database(`${environment.CONFIG_PATH}/db/db.sqlite`);
export const db = drizzle(sqlite, { schema });
export default db;

10
server/db/schema.ts Normal file
View file

@ -0,0 +1,10 @@
import { InferSelectModel } from "drizzle-orm";
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
export const schools = sqliteTable("schools", {
id: integer("id").primaryKey({ autoIncrement: true }),
name: text("name"),
abbreviation: text("abbreviation"),
});
export type SelectSchoolType = InferSelectModel<typeof schools>;

27
server/environment.ts Normal file
View file

@ -0,0 +1,27 @@
import { z } from "zod";
import { fromError } from "zod-validation-error";
const environmentSchema = z.object({
ENVIRONMENT: z.string(),
LOG_LEVEL: z.string(),
SAVE_LOGS: z.string().transform((val) => val === "true"),
PORT: z.string(),
CONFIG_PATH: z.string(),
});
const environment = {
ENVIRONMENT: (process.env.ENVIRONMENT as string) || "dev",
LOG_LEVEL: (process.env.LOG_LEVEL as string) || "debug",
SAVE_LOGS: (process.env.SAVE_LOGS as string) || "false",
PORT: (process.env.PORT as string) || "3000",
CONFIG_PATH: process.env.CONFIG_PATH as string,
};
const parsedConfig = environmentSchema.safeParse(environment);
if (!parsedConfig.success) {
const errors = fromError(parsedConfig.error);
throw new Error(`Invalid environment configuration: ${errors}`);
}
export default parsedConfig.data;

36
server/index.ts Normal file
View file

@ -0,0 +1,36 @@
import express, { Request, Response } from "express";
import next from "next";
import { parse } from "url";
import environment from "./environment";
import logger from "@/server/logger";
import helmet from "helmet";
import cors from "cors";
import unauth from "@server/routers/unauth";
const dev = environment.ENVIRONMENT !== "prod";
const app = next({ dev });
const handle = app.getRequestHandler();
const port = environment.PORT;
app.prepare().then(() => {
const server = express();
server.use(helmet());
server.use(cors());
const prefix = `/api`;
server.use(prefix, express.json(), unauth);
server.all("*", (req: Request, res: Response) => {
const parsedUrl = parse(req.url!, true);
handle(req, res, parsedUrl);
});
server.listen(port, (err?: any) => {
if (err) {
throw err;
}
logger.info(`Server is running on http://localhost:${port}`);
});
});

67
server/logger.ts Normal file
View file

@ -0,0 +1,67 @@
import "winston-daily-rotate-file";
import environment from "@server/environment";
import * as winston from "winston";
const hformat = winston.format.printf(
({ level, label, message, timestamp, ...metadata }) => {
let msg = `${timestamp} [${level}]${label ? `[${label}]` : ""}: ${message} `;
if (Object.keys(metadata).length > 0) {
msg += JSON.stringify(metadata);
}
return msg;
},
);
const transports: any = [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.splat(),
winston.format.timestamp(),
hformat,
),
}),
];
if (environment.SAVE_LOGS) {
transports.push(
new winston.transports.DailyRotateFile({
filename: `${environment.CONFIG_PATH}/logs/pangolin-%DATE%.log`,
datePattern: "YYYY-MM-DD",
zippedArchive: true,
maxSize: "20m",
maxFiles: "7d",
createSymlink: true,
symlinkName: "pangolin.log",
}),
);
transports.push(
new winston.transports.DailyRotateFile({
filename: `${environment.CONFIG_PATH}/logs/.machinelogs-%DATE%.json`,
datePattern: "YYYY-MM-DD",
zippedArchive: true,
maxSize: "20m",
maxFiles: "1d",
createSymlink: true,
symlinkName: ".machinelogs.json",
format: winston.format.combine(
winston.format.timestamp(),
winston.format.splat(),
winston.format.json(),
),
}),
);
}
const logger = winston.createLogger({
level: environment.LOG_LEVEL.toLowerCase(),
format: winston.format.combine(
winston.format.splat(),
winston.format.timestamp(),
hformat,
),
transports,
});
export default logger;

9
server/routers/unauth.ts Normal file
View file

@ -0,0 +1,9 @@
import { Router } from "express";
const unauth = Router();
unauth.get("/", (_, res) => {
res.status(200).json({ message: "Healthy" });
});
export default unauth;

Binary file not shown.

Binary file not shown.

View file

@ -1,27 +1,3 @@
@tailwind base; @tailwind base;
@tailwind components; @tailwind components;
@tailwind utilities; @tailwind utilities;
:root {
--background: #ffffff;
--foreground: #171717;
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
}
@layer utilities {
.text-balance {
text-wrap: balance;
}
}

View file

@ -1,35 +1,19 @@
import type { Metadata } from "next"; import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css"; import "./globals.css";
const geistSans = localFont({
src: "./fonts/GeistVF.woff",
variable: "--font-geist-sans",
weight: "100 900",
});
const geistMono = localFont({
src: "./fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
weight: "100 900",
});
export const metadata: Metadata = { export const metadata: Metadata = {
title: "Create Next App", title: "Pangolin",
description: "Generated by create next app", description: "",
}; };
export default function RootLayout({ export default function RootLayout({
children, children,
}: Readonly<{ }: Readonly<{
children: React.ReactNode; children: React.ReactNode;
}>) { }>) {
return ( return (
<html lang="en"> <html lang="en">
<body <body>{children}</body>
className={`${geistSans.variable} ${geistMono.variable} antialiased`} </html>
> );
{children}
</body>
</html>
);
} }

View file

@ -1,101 +1,7 @@
import Image from "next/image"; export default function Page() {
return (
export default function Home() { <>
return ( <h1>Hello world</h1>
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]"> </>
<main className="flex flex-col gap-8 row-start-2 items-center sm:items-start"> );
<Image
className="dark:invert"
src="https://nextjs.org/icons/next.svg"
alt="Next.js logo"
width={180}
height={38}
priority
/>
<ol className="list-inside list-decimal text-sm text-center sm:text-left font-[family-name:var(--font-geist-mono)]">
<li className="mb-2">
Get started by editing{" "}
<code className="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-semibold">
src/app/page.tsx
</code>
.
</li>
<li>Save and see your changes instantly.</li>
</ol>
<div className="flex gap-4 items-center flex-col sm:flex-row">
<a
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5"
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
className="dark:invert"
src="https://nextjs.org/icons/vercel.svg"
alt="Vercel logomark"
width={20}
height={20}
/>
Deploy now
</a>
<a
className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44"
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Read our docs
</a>
</div>
</main>
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/file.svg"
alt="File icon"
width={16}
height={16}
/>
Learn
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/window.svg"
alt="Window icon"
width={16}
height={16}
/>
Examples
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/globe.svg"
alt="Globe icon"
width={16}
height={16}
/>
Go to nextjs.org
</a>
</footer>
</div>
);
} }

View file

@ -1,19 +1,19 @@
import type { Config } from "tailwindcss"; import type { Config } from "tailwindcss";
const config: Config = { const config: Config = {
content: [ content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}", "./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}", "./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}", "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
], ],
theme: { theme: {
extend: { extend: {
colors: { colors: {
background: "var(--background)", background: "var(--background)",
foreground: "var(--foreground)", foreground: "var(--foreground)",
}, },
},
}, },
}, plugins: [],
plugins: [],
}; };
export default config; export default config;

View file

@ -1,26 +1,29 @@
{ {
"compilerOptions": { "compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"], "lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true, "allowJs": true,
"skipLibCheck": true, "skipLibCheck": true,
"strict": true, "strict": true,
"noEmit": true, "noEmit": true,
"esModuleInterop": true, "esModuleInterop": true,
"module": "esnext", "module": "esnext",
"moduleResolution": "bundler", "moduleResolution": "bundler",
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"jsx": "preserve", "jsx": "preserve",
"incremental": true, "incremental": true,
"plugins": [ "baseUrl": "src",
{ "paths": {
"name": "next" "@/*": ["../*"],
} "@server/*": ["../server/*"],
], "@app/*": ["*"]
"paths": { },
"@/*": ["./src/*"] "plugins": [
} {
}, "name": "next"
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], }
"exclude": ["node_modules"] ]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
} }