-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create basic architecture #1
Create basic architecture #1
Conversation
Maybe add helmet, cors, swagger and env plugin as well? |
Also I would personally love to see typescript! Together with ESM. |
Is there perhaps a debug bar plugin for fastify which can give us metrics on the performance of our server,similar to the debug bar we see in the symfony demo and laravel framework? I can't seem to find one. On the note of the roadmap what is your initial ideas on the features and use cases of this project? |
I'll add TypeScript tomorrow. I'm not sure the way I've organized the plugins is relevant @melroy89. Also, I'm reading Matteo's book on the subject of Fastify so I need to take more time to think about what I'm doing but the good news is I've got lots of time to work on this demo.
I don't have many ideas, some sort of task app, or a blog/post might be a good start but I can't think of anything more fun and original. I'm open to suggestions! |
Autoloader is good to use indeed! And also the best way of doing it IMO. I personally have my files within the I personally added the Swagger |
Not that I know of. I do know But again, no built-in "debug bar" web UI element. I think fastify-metrics is the closest. And of course just use the default Pino logging?? |
Ho, yep, I should add this plugin too I think. |
@jean-michelet You are right on track with Type Providers for TS. Focused on schema validation, for both out- and incoming requests/responses. Do not forget an example of declaring your own version/extending the Maybe also add a general example for authentication using I believe another good practice is to configure this.app.setErrorHandler((err, req, reply) => {
req.log.error({ err })
reply.status(err.statusCode || 500)
reply.send(err)
})
this.app.setNotFoundHandler(async (req, reply) => {
req.log.info({ req }, 'request was not found')
reply.code(404)
return { message: 'Not found' }
}) Maybe you also want to add an caching example. Last but not least, best practices for logging. {
level: 'info',
transport: {
target: 'pino-pretty',
options: {
translateTime: 'HH:MM:ss Z',
ignore: 'pid,hostname',
},
},
} Here a full example, what I have (do whatever you want with this info): const environment = process.env.NODE_ENV || 'production'
const envToLogger: {
[key: string]: object | boolean
} = {
development: {
level: 'info',
transport: {
target: 'pino-pretty',
options: {
translateTime: 'HH:MM:ss Z',
ignore: 'pid,hostname',
},
},
},
production: true,
test: false,
}
this.app = Fastify({
logger: envToLogger[environment] ?? true,
ajv: {
customOptions: {
coerceTypes: 'array', // change data type of data to match type keyword
removeAdditional: 'all',// Remove additional body properties
},
},
}).withTypeProvider<JsonSchemaToTsProvider>() Ps. MAYBE... a MySQL or other database integration example? Like |
Don't understand how to it. |
I worked locally to add a rate limiter, but I think we should merge this before, otherwise I'll make your reviews obsolete. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@Fdawgs you are now blocking the merge (request for change) ;). Is there still something we need to fix? |
Just haven't had the time to review due to work being stupidly busy. Will take a look this coming week! |
Ah no problem, thanks for your heads up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to explicitly register this inside each route and define the methods
option to ensure each route returns the correct values in the Access-Control-Allow-Methods
header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to explicitly register this inside each route
Not sure to understand what you mean, the plugin is designed to be configured globally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few minor tweaks.
src/plugins/external/cors.ts
Outdated
export const autoConfig: FastifyCorsOptions = { | ||
methods: ['GET', 'POST', 'PUT', 'DELETE'] | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do a more precise configuration when we will set up the front end, cf #2
Co-authored-by: Frazer Smith <[email protected]> Signed-off-by: Jean <[email protected]>
Nice. It's approved! 🙏🎉. Well done @jean-michelet |
Can it be merged plz? |
You should now have enough permissions to land it yourself! Go ahead, lgtm! |
Proposal for Basic Fastify API Architecture
This PR proposes a basic architecture for a Fastify API. It does not contain any features. I suggest we open an issue and create a roadmap for the next steps.
The base was generated by (and designed to work with) fastify-cli.
Core plugins used:
helmet
,cors
,swagger
,swagger-ui
,env
,sensible
,under-pressure
,mysql
fastify-cli
generates a lot of comments, but I decided to keep them because they are educational.I've also added a
server.ts
file just to show how not to depend onfastify-cli
to launch the app.Wait for your feedbacks.