-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
132 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@acme/api-trpc", | ||
"version": "1.0.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"clean": "git clean -xdf .next .turbo node_modules", | ||
"dev": "pnpm with-env tsx watch --clear-screen=false ./src/index.ts", | ||
"format": "prettier --check . --ignore-path ../../.prettierignore", | ||
"jest": "pnpm run -C ../.. jest", | ||
"jest:i": "RUN_JEST_INTEGRATION_TESTS=1 pnpm run jest", | ||
"lint": "eslint .", | ||
"test": "pnpm run jest $PWD", | ||
"test:i": "pnpm run jest:i $PWD", | ||
"typecheck": "tsc --noEmit", | ||
"with-env": "dotenv -e ../../.env --" | ||
}, | ||
"dependencies": { | ||
"@acme/api": "workspace:*", | ||
"@acme/constants": "workspace:*", | ||
"@acme/db": "workspace:*", | ||
"@acme/paths": "workspace:*", | ||
"@andrao/tools": "^1.0.0", | ||
"@t3-oss/env-nextjs": "^0.9.2", | ||
"@trpc/server": "next", | ||
"cors": "^2.8.5", | ||
"express": "^4.19.2", | ||
"zod": "^3.23.8" | ||
}, | ||
"devDependencies": { | ||
"@types/cors": "^2.8.17", | ||
"@types/express": "^4.17.21", | ||
"@types/supertest": "^6.0.2", | ||
"supertest": "^7.0.0", | ||
"tsx": "^4.16.5" | ||
} | ||
} |
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,43 @@ | ||
import { PORTS } from '@acme/paths'; | ||
import { createEnv } from '@t3-oss/env-nextjs'; | ||
import { z } from 'zod'; | ||
|
||
/** | ||
* @const env | ||
* @description Environment variables for the NextJS app | ||
* @see https://vercel.com/docs/projects/environment-variables/system-environment-variables for default Vercel env vars | ||
*/ | ||
export const env = createEnv({ | ||
/** | ||
* Server-side | ||
*/ | ||
server: {}, | ||
|
||
/** | ||
* Client-side | ||
* - For them to be exposed, prefix with `NEXT_PUBLIC_`. | ||
*/ | ||
client: {}, | ||
|
||
/** | ||
* Env vars shared between server & client | ||
* - Node defaults, environment | ||
*/ | ||
shared: { | ||
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'), | ||
PORT: z.coerce.number().default(PORTS.api_trpc), | ||
}, | ||
|
||
/** | ||
* Destructure all variables from `process.env` to make sure they aren't tree-shaken away. | ||
*/ | ||
runtimeEnv: { | ||
NODE_ENV: process.env.NODE_ENV, | ||
PORT: process.env.PORT, | ||
}, | ||
|
||
skipValidation: | ||
!!process.env.CI || | ||
!!process.env.SKIP_ENV_VALIDATION || | ||
process.env.npm_lifecycle_event === 'lint', | ||
}); |
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,37 @@ | ||
import { APP_ROUTER } from '@acme/api'; | ||
import { dbx } from '@acme/db'; | ||
import { PATHS } from '@acme/paths'; | ||
import * as trpcExpress from '@trpc/server/adapters/express'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
import { env } from './env'; | ||
|
||
/** | ||
* @const app | ||
* @description Initialized express app | ||
*/ | ||
export const app = express(); | ||
|
||
/** | ||
* Enable CORS | ||
* @todo This enables CORS for all routes, consider enabling only for specific routes | ||
*/ | ||
app.use(cors({ credentials: true })); | ||
|
||
/** | ||
* Host tRPC router | ||
*/ | ||
app.use( | ||
PATHS.api.trpc, | ||
trpcExpress.createExpressMiddleware({ | ||
router: APP_ROUTER, | ||
createContext: ({ req }) => ({ dbx, env, headers: req.headers }), | ||
}), | ||
); | ||
|
||
/** | ||
* Start server & listen on port | ||
*/ | ||
export const server = app.listen(env.PORT, () => { | ||
console.log(`Server is running on port ${env.PORT}`); | ||
}); |
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,14 @@ | ||
{ | ||
"extends": "@andrao/tsconfig/base.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"~/*": ["./src/*"], | ||
"@ui/*": ["../../packages/@app-browser/ui/src/*"] | ||
}, | ||
"plugins": [{ "name": "next" }], | ||
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json" | ||
}, | ||
"include": ["src/env.js", "**/*.ts", "**/*.tsx"], | ||
"exclude": ["node_modules"] | ||
} |
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