diff options
Diffstat (limited to 'examples/with-prisma/apps/web')
| -rw-r--r-- | examples/with-prisma/apps/web/.gitignore | 34 | ||||
| -rw-r--r-- | examples/with-prisma/apps/web/README.md | 30 | ||||
| -rw-r--r-- | examples/with-prisma/apps/web/next-env.d.ts | 5 | ||||
| -rw-r--r-- | examples/with-prisma/apps/web/next.config.js | 6 | ||||
| -rw-r--r-- | examples/with-prisma/apps/web/package.json | 26 | ||||
| -rw-r--r-- | examples/with-prisma/apps/web/pages/api/users.ts | 34 | ||||
| -rw-r--r-- | examples/with-prisma/apps/web/pages/index.tsx | 8 | ||||
| -rw-r--r-- | examples/with-prisma/apps/web/tsconfig.json | 5 |
8 files changed, 148 insertions, 0 deletions
diff --git a/examples/with-prisma/apps/web/.gitignore b/examples/with-prisma/apps/web/.gitignore new file mode 100644 index 0000000..1437c53 --- /dev/null +++ b/examples/with-prisma/apps/web/.gitignore @@ -0,0 +1,34 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env.local +.env.development.local +.env.test.local +.env.production.local + +# vercel +.vercel diff --git a/examples/with-prisma/apps/web/README.md b/examples/with-prisma/apps/web/README.md new file mode 100644 index 0000000..4fae62a --- /dev/null +++ b/examples/with-prisma/apps/web/README.md @@ -0,0 +1,30 @@ +## Getting Started + +First, run the development server: + +```bash +yarn dev +``` + +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. + +You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file. + +[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`. + +The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. + +## 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/foundations/about-nextjs) - 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_source=github.com&utm_medium=referral&utm_campaign=turborepo-readme) from the creators of Next.js. + +Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. diff --git a/examples/with-prisma/apps/web/next-env.d.ts b/examples/with-prisma/apps/web/next-env.d.ts new file mode 100644 index 0000000..4f11a03 --- /dev/null +++ b/examples/with-prisma/apps/web/next-env.d.ts @@ -0,0 +1,5 @@ +/// <reference types="next" /> +/// <reference types="next/image-types/global" /> + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-prisma/apps/web/next.config.js b/examples/with-prisma/apps/web/next.config.js new file mode 100644 index 0000000..27b528b --- /dev/null +++ b/examples/with-prisma/apps/web/next.config.js @@ -0,0 +1,6 @@ +/** + * @type {import('next').NextConfig} + */ +module.exports = { + reactStrictMode: true, +}; diff --git a/examples/with-prisma/apps/web/package.json b/examples/with-prisma/apps/web/package.json new file mode 100644 index 0000000..2f0aaa7 --- /dev/null +++ b/examples/with-prisma/apps/web/package.json @@ -0,0 +1,26 @@ +{ + "private": true, + "name": "web", + "version": "1.0.0", + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start", + "lint": "next lint" + }, + "dependencies": { + "next": "latest", + "react": "^18.2.0", + "react-dom": "^18.2.0" + }, + "devDependencies": { + "@types/node": "^17.0.12", + "@types/react": "^18.0.22", + "@types/react-dom": "^18.0.7", + "config": "*", + "database": "*", + "eslint": "^7.32.0", + "tsconfig": "*", + "typescript": "^4.5.3" + } +} diff --git a/examples/with-prisma/apps/web/pages/api/users.ts b/examples/with-prisma/apps/web/pages/api/users.ts new file mode 100644 index 0000000..3f7b3f0 --- /dev/null +++ b/examples/with-prisma/apps/web/pages/api/users.ts @@ -0,0 +1,34 @@ +import { prisma } from "database"; + +import type { NextApiRequest, NextApiResponse } from "next"; + +/** + * Users + * + * @description A basic API endpoint to retrieve all the users in the database + */ +export default async function handler( + req: NextApiRequest, + res: NextApiResponse +) { + if (req.method !== "GET") { + res.setHeader("Allow", ["GET"]); + return res.status(405).end(`Method ${req.method} Not Allowed`); + } + + try { + const users = await prisma.user.findMany(); + if (!users) + throw { + message: "Failed to retrieve users", + status: 500, + }; + + return res.status(200).json({ + users, + }); + } catch ({ message = "An unknown error occured", status = 500 }) { + console.error({ message, status }); + return res.status(status).end(message); + } +} diff --git a/examples/with-prisma/apps/web/pages/index.tsx b/examples/with-prisma/apps/web/pages/index.tsx new file mode 100644 index 0000000..6e254b7 --- /dev/null +++ b/examples/with-prisma/apps/web/pages/index.tsx @@ -0,0 +1,8 @@ +export default function IndexPage() { + return ( + <div> + <h1>Hello World</h1> + <a href="/api/users">View Users</a> + </div> + ); +} diff --git a/examples/with-prisma/apps/web/tsconfig.json b/examples/with-prisma/apps/web/tsconfig.json new file mode 100644 index 0000000..a355365 --- /dev/null +++ b/examples/with-prisma/apps/web/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "tsconfig/nextjs.json", + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], + "exclude": ["node_modules"] +} |
