Skip to content

Commit 544215c

Browse files
authored
Merge pull request #786 from Lemoncode/feature/update-nextjs
Feature/update nextjs
2 parents 71755b4 + 37af226 commit 544215c

File tree

197 files changed

+1434
-1127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+1434
-1127
lines changed

04-frameworks/08-nextjs/00-boilerplate/api-server/config/routes.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

04-frameworks/08-nextjs/00-boilerplate/api-server/mock-data/data.json

Lines changed: 0 additions & 121 deletions
This file was deleted.

04-frameworks/08-nextjs/00-boilerplate/api-server/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
"description": "Car API",
55
"main": "index.js",
66
"scripts": {
7-
"mock-server": "json-server --routes ./config/routes.json --watch mock-data/data.json --port 3001"
7+
"mock-server": "tsx watch src/index.ts"
88
},
99
"author": "Lemoncode",
1010
"license": "MIT",
11+
"dependencies": {
12+
"@hono/node-server": "^1.12.2",
13+
"hono": "^4.5.11"
14+
},
1115
"devDependencies": {
12-
"json-server": "^0.17.3"
16+
"tsx": "^4.19.0"
1317
}
1418
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Hono } from 'hono';
2+
import { logger } from 'hono/logger';
3+
import { cors } from 'hono/cors';
4+
import { serve } from '@hono/node-server';
5+
import { serveStatic } from '@hono/node-server/serve-static';
6+
import { cars } from './mock-data';
7+
8+
let db = {
9+
cars,
10+
};
11+
12+
const app = new Hono();
13+
app.use(logger());
14+
app.use('/*', serveStatic({ root: './public' }));
15+
16+
app.use('/api/*', cors());
17+
18+
app.get('/api/cars', (context) => {
19+
return context.json(db.cars);
20+
});
21+
22+
app.get('/api/cars/:id', (context) => {
23+
return context.json(db.cars.find((c) => c.id === context.req.param('id')));
24+
});
25+
26+
app.put('/api/cars/:id', async (context) => {
27+
const id = context.req.param('id');
28+
const car = await context.req.json();
29+
db.cars = db.cars.map((c) =>
30+
c.id === id ? { ...c, isBooked: car.isBooked } : c
31+
);
32+
return context.body(null, 204);
33+
});
34+
35+
serve({ fetch: app.fetch, port: 3001 }, (info) => {
36+
console.log(`API running on ${info.port}`);
37+
});
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
export const cars = [
2+
{
3+
id: '1',
4+
name: 'Audi Q8 Automático',
5+
imageUrl: '/audi-q8.png',
6+
features: [
7+
'5 asientos',
8+
'5 puertas',
9+
'Automático',
10+
'4 maletas',
11+
'Aire acondicionado',
12+
],
13+
isBooked: false,
14+
},
15+
{
16+
id: '2',
17+
name: 'BMW X7',
18+
imageUrl: '/bmw-x7.png',
19+
features: [
20+
'7 asientos',
21+
'5 puertas',
22+
'Automático',
23+
'2 maletas',
24+
'Aire acondicionado',
25+
'GPS',
26+
],
27+
isBooked: false,
28+
},
29+
{
30+
id: '3',
31+
name: 'Citroen C4 Cactus',
32+
imageUrl: '/citroen-c4-cactus.png',
33+
features: [
34+
'5 asientos',
35+
'5 puertas',
36+
'Manual',
37+
'1 maleta',
38+
'Aire acondicionado',
39+
],
40+
isBooked: false,
41+
},
42+
{
43+
id: '4',
44+
name: 'Jaguar F-Pace Automático',
45+
imageUrl: '/jaguar-f-pace.png',
46+
features: [
47+
'5 asientos',
48+
'5 puertas',
49+
'Automático',
50+
'2 maletas',
51+
'Aire acondicionado',
52+
],
53+
isBooked: false,
54+
},
55+
{
56+
id: '5',
57+
name: 'Mercedes-Benz Clase G',
58+
imageUrl: '/mb-g.png',
59+
features: [
60+
'5 asientos',
61+
'5 puertas',
62+
'Automático',
63+
'2 maletas',
64+
'Aire acondicionado',
65+
],
66+
isBooked: false,
67+
},
68+
{
69+
id: '6',
70+
name: 'Mercedes-Benz Clase V',
71+
imageUrl: '/mb-v-klasse.png',
72+
features: [
73+
'7 asientos',
74+
'5 puertas',
75+
'Automático',
76+
'3 maletas',
77+
'Aire acondicionado',
78+
],
79+
isBooked: false,
80+
},
81+
{
82+
id: '7',
83+
name: 'Peugeot Rifter',
84+
imageUrl: '/peugeot-rifter.png',
85+
features: [
86+
'5 asientos',
87+
'5 puertas',
88+
'Manual',
89+
'2 maletas',
90+
'Aire acondicionado',
91+
],
92+
isBooked: false,
93+
},
94+
{
95+
id: '8',
96+
name: 'Porsche Macan',
97+
imageUrl: '/porsche-macan.png',
98+
features: ['5 asientos', '5 puertas', 'Manual', '2 maletas'],
99+
isBooked: false,
100+
},
101+
{
102+
id: '9',
103+
name: 'VW Touran',
104+
imageUrl: '/vw-touran.png',
105+
features: [
106+
'5 asientos',
107+
'5 puertas',
108+
'Manual',
109+
'2 maletas',
110+
'Aire acondicionado',
111+
],
112+
isBooked: false,
113+
},
114+
];

04-frameworks/08-nextjs/00-boilerplate/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"author": "Lemoncode",
1010
"license": "MIT",
1111
"dependencies": {
12-
"react": "^18.2.0",
13-
"react-dom": "^18.2.0"
12+
"react": "^18.3.1",
13+
"react-dom": "^18.3.1"
1414
},
1515
"devDependencies": {
16-
"@types/react": "^18.2.55",
17-
"@types/react-dom": "^18.2.19",
18-
"typescript": "^5.3.3"
16+
"@types/react": "^18.3.5",
17+
"@types/react-dom": "^18.3.0",
18+
"typescript": "^5.6.2"
1919
}
2020
}

04-frameworks/08-nextjs/01-config/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ _./package.json_
2828
"scripts": {
2929
+ "start": "next dev",
3030
"start:api-server": "cd api-server && npm run mock-server",
31-
"postinstall": "cd ./api-server && npm install",
32-
"clean": "rimraf .next"
31+
"postinstall": "cd ./api-server && npm install"
3332
},
3433
```
3534

36-
Before Nextjs 13, we used to create pages inside the `pages` folder and the rest of our files with our custom project structure. Now, with the new version, we must place all our files inside the `app` folder and every component will be a `React Server Component` by default.
35+
Before Nextjs 13, we used to create pages inside the `pages` folder and the rest of our files with our custom project structure. Now, with the new version, we can place files inside the `app` folder and every component will be a `React Server Component` by default.
3736

3837
[It's required create a `root layout`](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#root-layout-required) inside `app/layout.tsx` with the required <html> and <body> tags:
3938

04-frameworks/08-nextjs/01-config/api-server/config/routes.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)