├── prisma
├── dev.db
└── schema.prisma
├── static
├── favicon.ico
└── README.md
├── components
├── README.md
└── Logo.vue
├── .editorconfig
├── layouts
├── README.md
└── default.vue
├── pages
├── README.md
└── index.vue
├── assets
└── README.md
├── README.md
├── store
└── README.md
├── package.json
├── renovate.json
├── nuxt.config.js
├── .gitignore
└── api
└── index.js
/prisma/dev.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prisma/prisma-nuxt/HEAD/prisma/dev.db
--------------------------------------------------------------------------------
/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prisma/prisma-nuxt/HEAD/static/favicon.ico
--------------------------------------------------------------------------------
/components/README.md:
--------------------------------------------------------------------------------
1 | # COMPONENTS
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | The components directory contains your Vue.js Components.
6 |
7 | _Nuxt.js doesn't supercharge these components._
8 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/layouts/README.md:
--------------------------------------------------------------------------------
1 | # LAYOUTS
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | This directory contains your Application Layouts.
6 |
7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/views#layouts).
8 |
--------------------------------------------------------------------------------
/pages/README.md:
--------------------------------------------------------------------------------
1 | # PAGES
2 |
3 | This directory contains your Application Views and Routes.
4 | The framework reads all the `*.vue` files inside this directory and creates the router of your application.
5 |
6 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing).
7 |
--------------------------------------------------------------------------------
/assets/README.md:
--------------------------------------------------------------------------------
1 | # ASSETS
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | This directory contains your un-compiled assets such as LESS, SASS, or JavaScript.
6 |
7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked).
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # fullstack-nuxt
2 |
3 | ## Build Setup
4 |
5 | ```bash
6 | # install dependencies
7 | $ npm install
8 |
9 | # serve with hot reload at localhost:3000
10 | $ npm run dev
11 |
12 | # build for production and launch server
13 | $ npm run build
14 | $ npm run start
15 |
16 | # generate static project
17 | $ npm run generate
18 | ```
19 |
20 | For detailed explanation on how things work, check out [Nuxt.js docs](https://nuxtjs.org).
21 |
--------------------------------------------------------------------------------
/store/README.md:
--------------------------------------------------------------------------------
1 | # STORE
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | This directory contains your Vuex Store files.
6 | Vuex Store option is implemented in the Nuxt.js framework.
7 |
8 | Creating a file in this directory automatically activates the option in the framework.
9 |
10 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/vuex-store).
11 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fullstack-nuxt",
3 | "version": "1.0.0",
4 | "private": true,
5 | "scripts": {
6 | "dev": "nuxt",
7 | "build": "nuxt build",
8 | "start": "nuxt start",
9 | "generate": "nuxt generate"
10 | },
11 | "dependencies": {
12 | "@prisma/client": "5.8.0",
13 | "core-js": "^3.8.3",
14 | "express": "^4.17.1",
15 | "nuxt": "^2.14.12"
16 | },
17 | "devDependencies": {
18 | "prisma": "5.8.0"
19 | }
20 | }
--------------------------------------------------------------------------------
/static/README.md:
--------------------------------------------------------------------------------
1 | # STATIC
2 |
3 | **This directory is not required, you can delete it if you don't want to use it.**
4 |
5 | This directory contains your static files.
6 | Each file inside this directory is mapped to `/`.
7 | Thus you'd want to delete this README.md before deploying to production.
8 |
9 | Example: `/static/robots.txt` is mapped as `/robots.txt`.
10 |
11 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#static).
12 |
--------------------------------------------------------------------------------
/prisma/schema.prisma:
--------------------------------------------------------------------------------
1 | // This is your Prisma schema file,
2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema
3 |
4 | datasource db {
5 | provider = "sqlite"
6 | url = "file:./dev.db"
7 | }
8 |
9 | generator client {
10 | provider = "prisma-client-js"
11 | }
12 |
13 | model Post {
14 | id Int @id @default(autoincrement())
15 | title String
16 | content String?
17 | published Boolean @default(false)
18 | author User? @relation(fields: [authorId], references: [id])
19 | authorId Int?
20 | }
21 |
22 | model User {
23 | id Int @id @default(autoincrement())
24 | email String @unique
25 | name String?
26 | posts Post[]
27 | }
28 |
--------------------------------------------------------------------------------
/components/Logo.vue:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
24 |
36 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "semanticCommits": "enabled",
4 | "dependencyDashboard": true,
5 | "rebaseWhen": "behind-base-branch",
6 | "timezone": "Europe/Berlin",
7 | "schedule": ["every weekend"],
8 | "packageRules": [
9 | {
10 | "matchDepTypes": ["devDependencies"],
11 | "matchUpdateTypes": ["minor", "patch"],
12 | "groupName": "devDependencies",
13 | "groupSlug": "dev-dependencies",
14 | "schedule": ["every weekend"]
15 | },
16 | {
17 | "matchDepTypes": ["dependencies"],
18 | "matchUpdateTypes": ["minor", "patch"],
19 | "groupName": "dependencies",
20 | "groupSlug": "dependencies",
21 | "schedule": ["every weekend"]
22 | },
23 | {
24 | "matchPackagePatterns": ["@prisma/*"],
25 | "matchPackageNames": ["prisma"],
26 | "matchUpdateTypes": ["major", "minor", "patch"],
27 | "groupName": "Prisma Dependencies",
28 | "groupSlug": "prisma-deps",
29 | "schedule": ["after 6pm on Tuesday"]
30 | }
31 | ]
32 | }
33 |
--------------------------------------------------------------------------------
/nuxt.config.js:
--------------------------------------------------------------------------------
1 | export default {
2 | // Global page headers (https://go.nuxtjs.dev/config-head)
3 | head: {
4 | title: 'fullstack-nuxt',
5 | meta: [
6 | { charset: 'utf-8' },
7 | { name: 'viewport', content: 'width=device-width, initial-scale=1' },
8 | { hid: 'description', name: 'description', content: '' },
9 | ],
10 | link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
11 | },
12 |
13 | // Global CSS (https://go.nuxtjs.dev/config-css)
14 | css: [],
15 |
16 | // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
17 | plugins: [],
18 |
19 | // Auto import components (https://go.nuxtjs.dev/config-components)
20 | components: true,
21 |
22 | // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
23 | buildModules: [
24 | // https://go.nuxtjs.dev/eslint
25 | ],
26 |
27 | // Modules (https://go.nuxtjs.dev/config-modules)
28 | modules: [],
29 |
30 | // Build Configuration (https://go.nuxtjs.dev/config-build)
31 | build: {},
32 | serverMiddleware: [
33 | '~/api/index.js'
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/layouts/default.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
56 |
--------------------------------------------------------------------------------
/pages/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
fullstack-nuxt
6 |
24 |
25 |
26 |
27 |
28 |
31 |
32 |
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Node template
3 | # Logs
4 | /logs
5 | *.log
6 | npm-debug.log*
7 | yarn-debug.log*
8 | yarn-error.log*
9 |
10 | # Runtime data
11 | pids
12 | *.pid
13 | *.seed
14 | *.pid.lock
15 |
16 | # Directory for instrumented libs generated by jscoverage/JSCover
17 | lib-cov
18 |
19 | # Coverage directory used by tools like istanbul
20 | coverage
21 |
22 | # nyc test coverage
23 | .nyc_output
24 |
25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26 | .grunt
27 |
28 | # Bower dependency directory (https://bower.io/)
29 | bower_components
30 |
31 | # node-waf configuration
32 | .lock-wscript
33 |
34 | # Compiled binary addons (https://nodejs.org/api/addons.html)
35 | build/Release
36 |
37 | # Dependency directories
38 | node_modules/
39 | jspm_packages/
40 |
41 | # TypeScript v1 declaration files
42 | typings/
43 |
44 | # Optional npm cache directory
45 | .npm
46 |
47 | # Optional eslint cache
48 | .eslintcache
49 |
50 | # Optional REPL history
51 | .node_repl_history
52 |
53 | # Output of 'npm pack'
54 | *.tgz
55 |
56 | # Yarn Integrity file
57 | .yarn-integrity
58 |
59 | # dotenv environment variables file
60 | .env
61 |
62 | # parcel-bundler cache (https://parceljs.org/)
63 | .cache
64 |
65 | # next.js build output
66 | .next
67 |
68 | # nuxt.js build output
69 | .nuxt
70 |
71 | # Nuxt generate
72 | dist
73 |
74 | # vuepress build output
75 | .vuepress/dist
76 |
77 | # Serverless directories
78 | .serverless
79 |
80 | # IDE / Editor
81 | .idea
82 |
83 | # Service worker
84 | sw.*
85 |
86 | # macOS
87 | .DS_Store
88 |
89 | # Vim swap files
90 | *.swp
91 | yarn.lock
92 | package-lock.json
93 |
--------------------------------------------------------------------------------
/api/index.js:
--------------------------------------------------------------------------------
1 | import express from 'express'
2 | import { PrismaClient } from '@prisma/client'
3 |
4 | const prisma = new PrismaClient()
5 |
6 | const app = express()
7 | app.use(express.json())
8 |
9 | app.get('/drafts', async (req, res) => {
10 | const posts = await prisma.post.findMany({
11 | where: { published: false },
12 | include: { author: true }
13 | })
14 | res.json(posts)
15 | })
16 |
17 | app.post('/post', async (req, res) => {
18 | const { title, content, authorEmail } = req.body
19 |
20 | const post = await prisma.post.create({
21 | data: {
22 | title,
23 | content,
24 | author: {
25 | connect: {
26 | email: authorEmail
27 | }
28 | }
29 | }
30 | })
31 |
32 | res.status(200).json(post)
33 | })
34 |
35 | app.post(`/user`, async (req, res) => {
36 | const result = await prisma.user.create({
37 | data: {
38 | ...req.body,
39 | },
40 | })
41 | res.json(result)
42 | })
43 |
44 | app.put('/publish/:id', async (req, res) => {
45 | const { id } = req.params
46 | const post = await prisma.post.update({
47 | where: {
48 | id: parseInt(id),
49 | },
50 | data: { published: true },
51 | })
52 | res.json(post)
53 | })
54 |
55 | app.delete(`/post/:id`, async (req, res) => {
56 | const { id } = req.params
57 | const post = await prisma.post.delete({
58 | where: {
59 | id: parseInt(id),
60 | },
61 | })
62 | res.json(post)
63 | })
64 |
65 | app.get(`/post/:id`, async (req, res) => {
66 | const { id } = req.params
67 | const post = await prisma.post.findUnique({
68 | where: {
69 | id: parseInt(id),
70 | },
71 | include: { author: true }
72 | })
73 | res.json(post)
74 | })
75 |
76 | app.get('/feed', async (req, res) => {
77 | const posts = await prisma.post.findMany({
78 | where: { published: true },
79 | include: { author: true },
80 | })
81 | res.json(posts)
82 | })
83 |
84 | app.get('/filterPosts', async (req, res) => {
85 | const { searchString } = req.query
86 | const draftPosts = await prisma.post.findMany({
87 | where: {
88 | OR: [
89 | {
90 | title: {
91 | contains: searchString,
92 | },
93 | },
94 | {
95 | content: {
96 | contains: searchString,
97 | },
98 | },
99 | ],
100 | },
101 | })
102 | res.json(draftPosts)
103 | })
104 |
105 | export default {
106 | path: '/api',
107 | handler: app
108 | }
--------------------------------------------------------------------------------