Skip to content

Commit 05b412c

Browse files
committed
chore: update fastify to v4 and other fastify dependencies accordingly
BREAKING CHANGE: Due to changes in Fastify API, make sure you "await" buildRouter/buildAuthenticatedRouter
1 parent a524e41 commit 05b412c

14 files changed

+1820
-1035
lines changed

example/package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
"main": "index.js",
55
"license": "MIT",
66
"scripts": {
7-
"dev": "nodemon",
7+
"dev": "ts-node src/server",
88
"lint": "eslint src --ext ts"
99
},
1010
"dependencies": {
1111
"@adminjs/design-system": "^2.0.2",
12-
"@adminjs/mongoose": "^2.0.0",
1312
"@adminjs/fastify": "../",
14-
"fastify-static": "^4.2.2",
13+
"@adminjs/mongoose": "^2.0.0",
14+
"@fastify/static": "^6.5.0",
15+
"fastify": "^4.3.0",
1516
"mongoose": "^5.12.14",
1617
"nodemon": "^2.0.6",
17-
"ts-node": "^9.0.0"
18+
"react": "^18.2.0",
19+
"react-dom": "^18.2.0",
20+
"styled-components": "^5.3.5",
21+
"ts-node": "^10.9.1"
1822
},
1923
"devDependencies": {}
2024
}

example/src/admin/admin.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import AdminJS from 'adminjs';
44
import { createUserResource } from './resources/user/user.resource';
55
import { FastifyInstance } from 'fastify';
66

7-
const setupAdmin = async (app: FastifyInstance): Promise<void> => {
7+
const setupAdmin = async (app: FastifyInstance): Promise<AdminJS> => {
88
AdminJS.registerAdapter(MongooseAdapter);
9+
910
const admin = new AdminJS({
1011
rootPath: '/admin',
11-
resources: [createUserResource()],
12+
resources: [],
1213
});
1314

1415
await AdminJSFastify.buildRouter(
@@ -24,6 +25,8 @@ const setupAdmin = async (app: FastifyInstance): Promise<void> => {
2425
// },
2526
app
2627
);
28+
29+
return admin
2730
};
2831

2932
export default setupAdmin;

example/src/server.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import fastify from 'fastify';
1+
import Fastify from 'fastify';
22
import setupAdmin from './admin/admin';
33
import mongoose from 'mongoose';
4-
import fastifyStatic from 'fastify-static';
4+
import fastifyStatic from '@fastify/static';
55
import path from 'path';
66

7-
const app = fastify();
7+
const app = Fastify();
88
const port = 3000;
99

1010
const run = async (): Promise<void> => {
@@ -16,13 +16,16 @@ const run = async (): Promise<void> => {
1616
useUnifiedTopology: true,
1717
}
1818
);
19-
app.register(fastifyStatic, {
19+
await app.register(fastifyStatic, {
2020
root: path.join(__dirname, '../public'),
2121
prefix: '/public/',
2222
});
2323

24-
await setupAdmin(app);
25-
await app.listen(port);
24+
const admin = await setupAdmin(app);
25+
app.listen({ port }, (err, addr) => {
26+
if (err) { console.log(err) }
27+
else console.log(`App started on ${addr}${admin.options.rootPath}`)
28+
});
2629
} catch (err) {
2730
app.log.error(err);
2831
process.exit(1);

0 commit comments

Comments
 (0)