-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #41
- Loading branch information
Showing
15 changed files
with
27,606 additions
and
2 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
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,38 @@ | ||
datasource db { | ||
provider = "sqlite" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
model User { | ||
id String @id @default(cuid()) | ||
email String @unique | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
password Password? | ||
notes Note[] | ||
} | ||
|
||
model Password { | ||
hash String | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade) | ||
userId String @unique | ||
} | ||
|
||
model Note { | ||
id String @id @default(cuid()) | ||
title String | ||
body String | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade) | ||
userId String | ||
} |
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,10 @@ | ||
/.git | ||
/node_modules | ||
.dockerignore | ||
.env | ||
Dockerfile | ||
fly.toml | ||
|
||
/.cache | ||
/build | ||
/public/build |
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,54 @@ | ||
# syntax = docker/dockerfile:1 | ||
|
||
# Adjust NODE_VERSION as desired | ||
ARG NODE_VERSION=xxx | ||
FROM node:${NODE_VERSION}-slim as base | ||
|
||
LABEL fly_launch_runtime="Remix/Prisma" | ||
|
||
# Remix/Prisma app lives here | ||
WORKDIR /app | ||
|
||
# Set production environment | ||
ENV NODE_ENV="production" | ||
|
||
|
||
# Throw-away build stage to reduce size of final image | ||
FROM base as build | ||
|
||
# Install packages needed to build node modules | ||
RUN apt-get update -qq && \ | ||
apt-get install -y build-essential openssl pkg-config python-is-python3 | ||
|
||
# Install node modules | ||
COPY --link package-lock.json package.json ./ | ||
RUN npm ci --include=dev | ||
|
||
# Generate Prisma Client | ||
COPY --link prisma . | ||
RUN npx prisma generate | ||
|
||
# Copy application code | ||
COPY --link . . | ||
|
||
# Build application | ||
RUN npm run build | ||
|
||
# Remove development dependencies | ||
RUN npm prune --omit=dev | ||
|
||
|
||
# Final stage for app image | ||
FROM base | ||
|
||
# Install packages needed for deployment | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y openssl && \ | ||
rm -rf /var/lib/apt/lists /var/cache/apt/archives | ||
|
||
# Copy built application | ||
COPY --from=build /app /app | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
EXPOSE 3000 | ||
CMD [ "npm", "run", "start" ] |
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,42 @@ | ||
import { cssBundleHref } from "@remix-run/css-bundle"; | ||
import type { LinksFunction, LoaderArgs } from "@remix-run/node"; | ||
import { json } from "@remix-run/node"; | ||
import { | ||
Links, | ||
LiveReload, | ||
Meta, | ||
Outlet, | ||
Scripts, | ||
ScrollRestoration, | ||
} from "@remix-run/react"; | ||
|
||
import { getUser } from "~/session.server"; | ||
import stylesheet from "~/tailwind.css"; | ||
|
||
export const links: LinksFunction = () => [ | ||
{ rel: "stylesheet", href: stylesheet }, | ||
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []), | ||
]; | ||
|
||
export const loader = async ({ request }: LoaderArgs) => { | ||
return json({ user: await getUser(request) }); | ||
}; | ||
|
||
export default function App() { | ||
return ( | ||
<html lang="en" className="h-full"> | ||
<head> | ||
<meta charSet="utf-8" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1" /> | ||
<Meta /> | ||
<Links /> | ||
</head> | ||
<body className="h-full"> | ||
<Outlet /> | ||
<ScrollRestoration /> | ||
<Scripts /> | ||
<LiveReload /> | ||
</body> | ||
</html> | ||
); | ||
} |
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,97 @@ | ||
import { createCookieSessionStorage, redirect } from "@remix-run/node"; | ||
import invariant from "tiny-invariant"; | ||
|
||
import type { User } from "~/models/user.server"; | ||
import { getUserById } from "~/models/user.server"; | ||
|
||
invariant(process.env.SESSION_SECRET, "SESSION_SECRET must be set"); | ||
|
||
export const sessionStorage = createCookieSessionStorage({ | ||
cookie: { | ||
name: "__session", | ||
httpOnly: true, | ||
path: "/", | ||
sameSite: "lax", | ||
secrets: [process.env.SESSION_SECRET], | ||
secure: process.env.NODE_ENV === "production", | ||
}, | ||
}); | ||
|
||
const USER_SESSION_KEY = "userId"; | ||
|
||
export async function getSession(request: Request) { | ||
const cookie = request.headers.get("Cookie"); | ||
return sessionStorage.getSession(cookie); | ||
} | ||
|
||
export async function getUserId( | ||
request: Request | ||
): Promise<User["id"] | undefined> { | ||
const session = await getSession(request); | ||
const userId = session.get(USER_SESSION_KEY); | ||
return userId; | ||
} | ||
|
||
export async function getUser(request: Request) { | ||
const userId = await getUserId(request); | ||
if (userId === undefined) return null; | ||
|
||
const user = await getUserById(userId); | ||
if (user) return user; | ||
|
||
throw await logout(request); | ||
} | ||
|
||
export async function requireUserId( | ||
request: Request, | ||
redirectTo: string = new URL(request.url).pathname | ||
) { | ||
const userId = await getUserId(request); | ||
if (!userId) { | ||
const searchParams = new URLSearchParams([["redirectTo", redirectTo]]); | ||
throw redirect(`/login?${searchParams}`); | ||
} | ||
return userId; | ||
} | ||
|
||
export async function requireUser(request: Request) { | ||
const userId = await requireUserId(request); | ||
|
||
const user = await getUserById(userId); | ||
if (user) return user; | ||
|
||
throw await logout(request); | ||
} | ||
|
||
export async function createUserSession({ | ||
request, | ||
userId, | ||
remember, | ||
redirectTo, | ||
}: { | ||
request: Request; | ||
userId: string; | ||
remember: boolean; | ||
redirectTo: string; | ||
}) { | ||
const session = await getSession(request); | ||
session.set(USER_SESSION_KEY, userId); | ||
return redirect(redirectTo, { | ||
headers: { | ||
"Set-Cookie": await sessionStorage.commitSession(session, { | ||
maxAge: remember | ||
? 60 * 60 * 24 * 7 // 7 days | ||
: undefined, | ||
}), | ||
}, | ||
}); | ||
} | ||
|
||
export async function logout(request: Request) { | ||
const session = await getSession(request); | ||
return redirect("/", { | ||
headers: { | ||
"Set-Cookie": await sessionStorage.destroySession(session), | ||
}, | ||
}); | ||
} |
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,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
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 @@ | ||
|
||
swap_size_mb = 512 | ||
|
||
[[http_service.checks]] | ||
grace_period = "10s" | ||
interval = "30s" | ||
method = "GET" | ||
timeout = "5s" | ||
path = "/healthcheck" | ||
|
||
[deploy] | ||
release_command = "npx prisma migrate deploy" |
Oops, something went wrong.