Skip to content

Commit df2ccc5

Browse files
feat(_official-blog-tutorial): update to latest indie-stack (#318)
1 parent 1796b39 commit df2ccc5

File tree

7 files changed

+61
-54
lines changed

7 files changed

+61
-54
lines changed

_official-blog-tutorial/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ FROM base as deps
1313
WORKDIR /myapp
1414

1515
ADD package.json .npmrc ./
16-
RUN npm install --production=false
16+
RUN npm install --include=dev
1717

1818
# Setup production node_modules
1919
FROM base as production-deps
@@ -22,7 +22,7 @@ WORKDIR /myapp
2222

2323
COPY --from=deps /myapp/node_modules /myapp/node_modules
2424
ADD package.json .npmrc ./
25-
RUN npm prune --production
25+
RUN npm prune --omit=dev
2626

2727
# Build the app
2828
FROM base as build
Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
import { PrismaClient } from "@prisma/client";
22

3-
let prisma: PrismaClient;
3+
import { singleton } from "./singleton.server";
44

5-
declare global {
6-
var __db__: PrismaClient;
7-
}
8-
9-
// this is needed because in development we don't want to restart
10-
// the server with every change, but we want to make sure we don't
11-
// create a new connection to the DB with every change either.
12-
// in production we'll have a single connection to the DB.
13-
if (process.env.NODE_ENV === "production") {
14-
prisma = new PrismaClient();
15-
} else {
16-
if (!global.__db__) {
17-
global.__db__ = new PrismaClient();
18-
}
19-
prisma = global.__db__;
20-
prisma.$connect();
21-
}
5+
// Hard-code a unique key, so we can look up the client when this module gets re-imported
6+
const prisma = singleton("prisma", () => new PrismaClient());
7+
prisma.$connect();
228

239
export { prisma };
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Since the dev server re-requires the bundle, do some shenanigans to make
2+
// certain things persist across that 😆
3+
// Borrowed/modified from https://github.com/jenseng/abuse-the-platform/blob/2993a7e846c95ace693ce61626fa072174c8d9c7/app/utils/singleton.ts
4+
5+
export const singleton = <Value>(
6+
name: string,
7+
valueFactory: () => Value
8+
): Value => {
9+
const g = global as any;
10+
g.__singletons ??= {};
11+
g.__singletons[name] ??= valueFactory();
12+
return g.__singletons[name];
13+
};

_official-blog-tutorial/fly.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
app = "blog-tutorial-ffb5"
1+
app = "blog-tutorial"
22

33
kill_signal = "SIGINT"
44
kill_timeout = 5

_official-blog-tutorial/package.json

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"sideEffects": false,
44
"scripts": {
55
"build": "remix build",
6-
"dev": "cross-env NODE_ENV=development binode --require ./mocks -- @remix-run/dev:remix dev",
6+
"dev": "remix dev -c \"npm run dev:serve\"",
7+
"dev:serve": "binode --require ./mocks -- @remix-run/serve:remix-serve ./build",
78
"format": "prettier --write .",
89
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
910
"setup": "prisma generate && prisma migrate deploy && prisma db seed",
@@ -23,58 +24,55 @@
2324
"/public/build"
2425
],
2526
"dependencies": {
26-
"@prisma/client": "^4.13.0",
27+
"@prisma/client": "^4.16.2",
28+
"@remix-run/css-bundle": "*",
2729
"@remix-run/node": "*",
2830
"@remix-run/react": "*",
2931
"@remix-run/serve": "*",
3032
"bcryptjs": "^2.4.3",
31-
"isbot": "^3.6.10",
33+
"isbot": "^3.6.13",
3234
"marked": "^4.3.0",
3335
"react": "^18.2.0",
3436
"react-dom": "^18.2.0",
3537
"tiny-invariant": "^1.3.1"
3638
},
3739
"devDependencies": {
38-
"@faker-js/faker": "^7.6.0",
39-
"@remix-run/css-bundle": "*",
40+
"@faker-js/faker": "^8.0.2",
4041
"@remix-run/dev": "*",
4142
"@remix-run/eslint-config": "*",
4243
"@testing-library/cypress": "^9.0.0",
43-
"@testing-library/jest-dom": "^5.16.5",
44-
"@testing-library/react": "^14.0.0",
45-
"@testing-library/user-event": "^14.4.3",
44+
"@testing-library/jest-dom": "^5.17.0",
4645
"@types/bcryptjs": "^2.4.2",
47-
"@types/eslint": "^8.37.0",
48-
"@types/marked": "^4.3.0",
49-
"@types/node": "^18.16.5",
50-
"@types/react": "^18.2.6",
51-
"@types/react-dom": "^18.2.4",
52-
"@vitejs/plugin-react": "^3.1.0",
53-
"@vitest/coverage-c8": "^0.31.0",
54-
"autoprefixer": "^10.4.14",
46+
"@types/eslint": "^8.44.2",
47+
"@types/marked": "^4.3.1",
48+
"@types/node": "^18.17.5",
49+
"@types/react": "^18.2.20",
50+
"@types/react-dom": "^18.2.7",
51+
"@vitejs/plugin-react": "^4.0.4",
52+
"@vitest/coverage-v8": "^0.34.1",
53+
"autoprefixer": "^10.4.15",
5554
"binode": "^1.0.5",
56-
"c8": "^7.13.0",
5755
"cookie": "^0.5.0",
5856
"cross-env": "^7.0.3",
59-
"cypress": "^12.10.0",
60-
"eslint": "^8.40.0",
61-
"eslint-config-prettier": "^8.8.0",
62-
"eslint-plugin-cypress": "^2.13.3",
63-
"happy-dom": "^9.8.0",
64-
"msw": "^1.2.1",
57+
"cypress": "^12.17.3",
58+
"eslint": "^8.47.0",
59+
"eslint-config-prettier": "^8.10.0",
60+
"eslint-plugin-cypress": "^2.14.0",
61+
"happy-dom": "^10.9.0",
62+
"msw": "^1.2.3",
6563
"npm-run-all": "^4.1.5",
66-
"postcss": "^8.4.23",
67-
"prettier": "2.8.8",
68-
"prettier-plugin-tailwindcss": "^0.2.8",
69-
"prisma": "^4.13.0",
64+
"postcss": "^8.4.27",
65+
"prettier": "3.0.1",
66+
"prettier-plugin-tailwindcss": "^0.5.2",
67+
"prisma": "^4.16.2",
7068
"start-server-and-test": "^2.0.0",
71-
"tailwindcss": "^3.3.2",
69+
"tailwindcss": "^3.3.3",
7270
"ts-node": "^10.9.1",
7371
"tsconfig-paths": "^4.2.0",
74-
"typescript": "^5.0.4",
75-
"vite": "^4.3.5",
72+
"typescript": "^5.1.6",
73+
"vite": "^4.4.9",
7674
"vite-tsconfig-paths": "^3.6.0",
77-
"vitest": "^0.31.0"
75+
"vitest": "^0.34.1"
7876
},
7977
"engines": {
8078
"node": ">=14"

_official-blog-tutorial/remix.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
module.exports = {
33
cacheDirectory: "./node_modules/.cache/remix",
44
future: {
5+
v2_dev: true,
56
v2_errorBoundary: true,
7+
v2_headers: true,
68
v2_meta: true,
79
v2_normalizeFormMethod: true,
810
v2_routeConvention: true,
911
},
1012
ignoredRouteFiles: ["**/.*", "**/*.test.{js,jsx,ts,tsx}"],
1113
postcss: true,
14+
serverModuleFormat: "cjs",
1215
tailwind: true,
1316
};

_official-blog-tutorial/start.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
#!/bin/sh
1+
#!/bin/sh -ex
22

33
# This file is how Fly starts the server (configured in fly.toml). Before starting
44
# the server though, we need to run any prisma migrations that haven't yet been
55
# run, which is why this file exists in the first place.
66
# Learn more: https://community.fly.io/t/sqlite-not-getting-setup-properly/4386
77

8-
set -ex
8+
# allocate swap space
9+
fallocate -l 512M /swapfile
10+
chmod 0600 /swapfile
11+
mkswap /swapfile
12+
echo 10 > /proc/sys/vm/swappiness
13+
swapon /swapfile
14+
echo 1 > /proc/sys/vm/overcommit_memory
15+
916
npx prisma migrate deploy
1017
npm run start

0 commit comments

Comments
 (0)