Skip to content

Commit 9183a1b

Browse files
committed
feat: change fastify to nextjs
1 parent e386a5a commit 9183a1b

14 files changed

+1217
-693
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ DATABASE_URL="mysql://rideplus:rideplus@localhost:3306/rideplus?schema=public"
88
# MYSQL_PORT="3306"
99

1010
# Clerk
11+
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=""
1112
CLERK_PUBLISHABLE_KEY=""
1213
CLERK_SECRET_KEY=""

apps/server/next.config.mjs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
3+
* for Docker builds.
4+
*/
5+
await import("./src/env.mjs");
6+
7+
/** @type {import("next").NextConfig} */
8+
const config = {
9+
reactStrictMode: true,
10+
transpilePackages: ["@rideplus/api", "@rideplus/auth"],
11+
output: "standalone",
12+
13+
/**
14+
* If you have `experimental: { appDir: true }` set, then you must comment the below `i18n` config
15+
* out.
16+
*
17+
* @see https://github.com/vercel/next.js/issues/41980
18+
*/
19+
};
20+
export default config;

apps/server/package.json

+27-17
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
{
22
"name": "@rideplus/server",
33
"version": "0.1.0",
4-
"main": "src/index.tsx",
54
"private": true,
65
"scripts": {
7-
"build": "tsup",
8-
"start": "pnpm with-env node dist/index.js",
9-
"dev": "pnpm with-env tsx watch --clear-screen=false src/index.ts",
6+
"build": "pnpm with-env next build",
7+
"dev": "pnpm with-env next dev",
8+
"lint": "next lint",
9+
"start": "pnpm with-env next start",
1010
"type-check": "tsc --noEmit",
11-
"lint": "eslint .",
12-
"lint:fix": "pnpm lint --fix",
11+
"clean": "git clean -xdf .next .turbo node_modules",
1312
"with-env": "dotenv -e ../../.env --"
1413
},
1514
"dependencies": {
16-
"@clerk/fastify": "^0.4.4",
17-
"@rideplus/api": "0.1.0",
18-
"@t3-oss/env-core": "^0.3.1",
19-
"@trpc/server": "^10.27.1",
20-
"fastify": "^4.17.0",
21-
"fastify-plugin": "^4.5.0",
22-
"superjson": "1.9.1",
15+
"@clerk/nextjs": "^4.19.0",
16+
"@rideplus/api": "^0.1.0",
17+
"@t3-oss/env-nextjs": "^0.3.1",
18+
"@tanstack/react-query": "^4.29.7",
19+
"@trpc/next": "^10.26.0",
20+
"@trpc/react-query": "^10.26.0",
21+
"@trpc/server": "^10.26.0",
22+
"next": "^13.4.2",
23+
"react": "18.2.0",
24+
"react-dom": "18.2.0",
25+
"superjson": "1.12.2",
2326
"zod": "^3.21.4"
2427
},
2528
"devDependencies": {
26-
"@rideplus/eslint-config": "^0.1.0",
29+
"@types/eslint": "^8.37.0",
30+
"@types/node": "^18.16.0",
31+
"@types/react": "^18.2.6",
32+
"@types/react-dom": "^18.2.4",
33+
"@typescript-eslint/eslint-plugin": "^5.59.6",
34+
"@typescript-eslint/parser": "^5.59.6",
2735
"dotenv-cli": "^7.2.1",
2836
"eslint": "^8.40.0",
29-
"pino-pretty": "^10.0.0",
30-
"tsup": "^6.7.0",
31-
"tsx": "^3.12.7"
37+
"eslint-config-next": "^13.4.2",
38+
"typescript": "^5.0.4"
39+
},
40+
"ct3aMetadata": {
41+
"initVersion": "7.13.1"
3242
}
3343
}

apps/server/src/env.ts apps/server/src/env.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { createEnv } from "@t3-oss/env-core";
1+
import { createEnv } from "@t3-oss/env-nextjs";
22
import { z } from "zod";
33

44
export const env = createEnv({
55
server: {
66
NODE_ENV: z
77
.enum(["development", "production", "test"])
88
.default("development"),
9-
CLERK_PUBLISHABLE_KEY: z.string().min(1),
9+
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(1),
1010
CLERK_SECRET_KEY: z.string().min(1),
1111
},
1212
client: {},
13-
clientPrefix: "",
1413
runtimeEnv: {
1514
NODE_ENV: process.env.NODE_ENV,
16-
CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY,
15+
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
16+
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
1717
CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY,
1818
},
1919
skipValidation: !!process.env.CI || !!process.env.SKIP_ENV_VALIDATION,

apps/server/src/index.ts

-47
This file was deleted.

apps/server/src/middleware.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { authMiddleware } from "@clerk/nextjs/server";
2+
3+
export default authMiddleware({
4+
publicRoutes: [/\/api\/trpc\/.*/],
5+
});
6+
7+
export const config = {
8+
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createNextApiHandler } from "@trpc/server/adapters/next";
2+
3+
import { appRouter, createTRPCContext } from "@rideplus/api";
4+
5+
// export API handler
6+
export default createNextApiHandler({
7+
router: appRouter,
8+
createContext: createTRPCContext,
9+
});

apps/server/tsconfig.json

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
{
2-
"extends": "../../tsconfig.json",
32
"compilerOptions": {
3+
"target": "es2017",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"checkJs": true,
7+
"skipLibCheck": true,
8+
"strict": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"noEmit": true,
11+
"esModuleInterop": true,
12+
"module": "esnext",
13+
"moduleResolution": "node",
14+
"resolveJsonModule": true,
15+
"isolatedModules": true,
16+
"jsx": "preserve",
17+
"incremental": true,
18+
"noUncheckedIndexedAccess": true,
419
"baseUrl": ".",
520
"paths": {
621
"~/*": ["./src/*"]
722
}
823
},
9-
"exclude": [],
10-
"include": ["**/*.ts", "**/*.cjs", "**/*.mjs"]
24+
"include": [
25+
".eslintrc.cjs",
26+
"next-env.d.ts",
27+
"**/*.ts",
28+
"**/*.tsx",
29+
"**/*.cjs",
30+
"**/*.mjs"
31+
],
32+
"exclude": ["node_modules"]
1133
}

apps/server/tsup.config.ts

-13
This file was deleted.

packages/api/src/trpc.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* The pieces you will need to use are documented accordingly near the end
88
*/
99
import { TRPCError, initTRPC } from "@trpc/server";
10-
import { type CreateFastifyContextOptions } from "@trpc/server/adapters/fastify";
10+
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
1111
import superjson from "superjson";
1212
import { ZodError } from "zod";
1313

@@ -51,7 +51,7 @@ export const createInnerTRPCContext = (opts: CreateContextOptions) => {
5151
* process every request that goes through your tRPC endpoint
5252
* @link https://trpc.io/docs/context
5353
*/
54-
export const createTRPCContext = (opts: CreateFastifyContextOptions) => {
54+
export const createTRPCContext = (opts: CreateNextContextOptions) => {
5555
// get the user session from the request
5656
const auth = getAuth(opts.req);
5757
return createInnerTRPCContext({

packages/auth/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"type-check": "tsc --noEmit"
1212
},
1313
"dependencies": {
14-
"@clerk/fastify": "^0.4.4",
14+
"@clerk/nextjs": "^4.19.0",
1515
"@rideplus/db": "0.1.0",
1616
"@t3-oss/env-nextjs": "^0.3.1",
1717
"zod": "^3.21.4"

packages/auth/src/get-session.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getAuth as $getAuth } from "@clerk/fastify";
1+
import { getAuth as $getAuth } from "@clerk/nextjs/server";
22

33
export type GetAuth = typeof $getAuth;
44
export type AuthObject = ReturnType<GetAuth>;

0 commit comments

Comments
 (0)