2 | Visit /cat or /cat?name={name} for data about cats
3 |
4 |
--------------------------------------------------------------------------------
/cat-consumer/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | // https://nuxt.com/docs/guide/concepts/typescript
3 | "extends": "./.nuxt/tsconfig.json"
4 | }
5 |
--------------------------------------------------------------------------------
/cat-provider/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | // https://nuxt.com/docs/guide/concepts/typescript
3 | "extends": "./.nuxt/tsconfig.json"
4 | }
5 |
--------------------------------------------------------------------------------
/cat-consumer/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | // https://nuxt.com/docs/api/configuration/nuxt-config
2 | export default defineNuxtConfig({
3 | devtools: { enabled: true }
4 | })
5 |
--------------------------------------------------------------------------------
/cat-provider/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | // https://nuxt.com/docs/api/configuration/nuxt-config
2 | export default defineNuxtConfig({
3 | devtools: { enabled: true },
4 | modules: ['@nuxtjs/supabase', 'nuxt-security'],
5 |
6 | security: {
7 | corsHandler: {
8 | origin: '*'
9 | }
10 | },
11 | })
12 |
--------------------------------------------------------------------------------
/cat-consumer/.gitignore:
--------------------------------------------------------------------------------
1 | # Nuxt dev/build outputs
2 | .output
3 | .data
4 | .nuxt
5 | .nitro
6 | .cache
7 | dist
8 |
9 | # Node dependencies
10 | node_modules
11 |
12 | # Logs
13 | logs
14 | *.log
15 |
16 | # Misc
17 | .DS_Store
18 | .fleet
19 | .idea
20 |
21 | # Local env files
22 | .env
23 | .env.*
24 | !.env.example
25 |
--------------------------------------------------------------------------------
/cat-provider/.gitignore:
--------------------------------------------------------------------------------
1 | # Nuxt dev/build outputs
2 | .output
3 | .data
4 | .nuxt
5 | .nitro
6 | .cache
7 | dist
8 |
9 | # Node dependencies
10 | node_modules
11 |
12 | # Logs
13 | logs
14 | *.log
15 |
16 | # Misc
17 | .DS_Store
18 | .fleet
19 | .idea
20 |
21 | # Local env files
22 | .env
23 | .env.*
24 | !.env.example
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Taking Nuxt to the Backend!
2 |
3 | This repository is an example project where there are two Nuxt applications:
4 |
5 | 1. Cat Provider -> Nuxt (Nitro) app that acts as a backend microservice. It connects to Supabase to fetch the data and return it to the user.
6 | 2. Cat Consumer -> Nuxt application that fetches the data from Cat Provider to display the data from this REST API to the user.
7 |
8 |
--------------------------------------------------------------------------------
/cat-consumer/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nuxt-app",
3 | "private": true,
4 | "type": "module",
5 | "scripts": {
6 | "build": "nuxt build",
7 | "dev": "nuxt dev",
8 | "generate": "nuxt generate",
9 | "preview": "nuxt preview",
10 | "postinstall": "nuxt prepare"
11 | },
12 | "devDependencies": {
13 | "@nuxt/devtools": "latest",
14 | "nuxt": "^3.7.4",
15 | "vue": "^3.3.4",
16 | "vue-router": "^4.2.5"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/cat-provider/server/api/cat.get.ts:
--------------------------------------------------------------------------------
1 | import { serverSupabaseClient } from "#supabase/server";
2 |
3 | export default defineEventHandler(async (event) => {
4 | const query = getQuery(event);
5 |
6 | const name = query.name;
7 |
8 | const client = await serverSupabaseClient(event);
9 |
10 | return !name
11 | ? (await client.from("cats").select("*")).data
12 | : (await client.from("cats").select("*").eq("name", name).single()).data;
13 | });
14 |
--------------------------------------------------------------------------------
/cat-provider/server/api/cat.delete.ts:
--------------------------------------------------------------------------------
1 | import { serverSupabaseClient } from "#supabase/server";
2 |
3 | export default defineEventHandler(async (event) => {
4 | const query = getQuery(event);
5 |
6 | const id = query.id;
7 |
8 | if (!id) throw createError({ statusCode: 400, statusMessage: "Bad Request" });
9 |
10 | const client = await serverSupabaseClient(event);
11 |
12 | const { data } = await client.from("cats").delete().eq("id", id);
13 |
14 | return { cat: data };
15 | });
16 |
--------------------------------------------------------------------------------
/cat-provider/server/api/cat.post.ts:
--------------------------------------------------------------------------------
1 | import { serverSupabaseClient } from "#supabase/server";
2 |
3 | export default defineEventHandler(async (event) => {
4 | const body = await readBody(event);
5 |
6 | if (!body || !body.image || !body.name)
7 | throw createError({ statusCode: 400, statusMessage: "Bad Request" });
8 |
9 | const client = await serverSupabaseClient(event);
10 |
11 | const { data } = await client.from("cats").insert(body);
12 |
13 | return { cat: data };
14 | });
15 |
--------------------------------------------------------------------------------
/cat-consumer/pages/cat/[...name].vue:
--------------------------------------------------------------------------------
1 |