Skip to content

Commit

Permalink
chore: update fastify to v4 and other fastify dependencies accordingly
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Due to changes in Fastify API, make sure you "await" buildRouter/buildAuthenticatedRouter
  • Loading branch information
dziraf committed Aug 2, 2022
1 parent a524e41 commit 05b412c
Show file tree
Hide file tree
Showing 14 changed files with 1,820 additions and 1,035 deletions.
12 changes: 8 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "nodemon",
"dev": "ts-node src/server",
"lint": "eslint src --ext ts"
},
"dependencies": {
"@adminjs/design-system": "^2.0.2",
"@adminjs/mongoose": "^2.0.0",
"@adminjs/fastify": "../",
"fastify-static": "^4.2.2",
"@adminjs/mongoose": "^2.0.0",
"@fastify/static": "^6.5.0",
"fastify": "^4.3.0",
"mongoose": "^5.12.14",
"nodemon": "^2.0.6",
"ts-node": "^9.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0",
"styled-components": "^5.3.5",
"ts-node": "^10.9.1"
},
"devDependencies": {}
}
7 changes: 5 additions & 2 deletions example/src/admin/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import AdminJS from 'adminjs';
import { createUserResource } from './resources/user/user.resource';
import { FastifyInstance } from 'fastify';

const setupAdmin = async (app: FastifyInstance): Promise<void> => {
const setupAdmin = async (app: FastifyInstance): Promise<AdminJS> => {
AdminJS.registerAdapter(MongooseAdapter);

const admin = new AdminJS({
rootPath: '/admin',
resources: [createUserResource()],
resources: [],
});

await AdminJSFastify.buildRouter(
Expand All @@ -24,6 +25,8 @@ const setupAdmin = async (app: FastifyInstance): Promise<void> => {
// },
app
);

return admin
};

export default setupAdmin;
15 changes: 9 additions & 6 deletions example/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fastify from 'fastify';
import Fastify from 'fastify';
import setupAdmin from './admin/admin';
import mongoose from 'mongoose';
import fastifyStatic from 'fastify-static';
import fastifyStatic from '@fastify/static';
import path from 'path';

const app = fastify();
const app = Fastify();
const port = 3000;

const run = async (): Promise<void> => {
Expand All @@ -16,13 +16,16 @@ const run = async (): Promise<void> => {
useUnifiedTopology: true,
}
);
app.register(fastifyStatic, {
await app.register(fastifyStatic, {
root: path.join(__dirname, '../public'),
prefix: '/public/',
});

await setupAdmin(app);
await app.listen(port);
const admin = await setupAdmin(app);
app.listen({ port }, (err, addr) => {
if (err) { console.log(err) }
else console.log(`App started on ${addr}${admin.options.rootPath}`)
});
} catch (err) {
app.log.error(err);
process.exit(1);
Expand Down
Loading

0 comments on commit 05b412c

Please sign in to comment.