Skip to content

Commit

Permalink
+ | middlewares
Browse files Browse the repository at this point in the history
trixden committed Mar 17, 2019
1 parent 5afea53 commit d58b796
Showing 3 changed files with 32 additions and 9 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
> # This library is not completed.
* [Why is this library need](#why-is-this-library-need)
* [Requirements](#requirements)
* [Getting started](#getting-started)
@@ -273,3 +271,29 @@ const parser: ContentTypeParser<FastifyRequest<IncomingMessage>> = function (req

export default parser;
```

## Middlewares

### Creating files

*using `javascript`:*
```javascript
exports.default = function (reqest, reply, next) {
...
next();
};
```

*using `typescript`:*
```typescript
import {ContentTypeParser, FastifyRequest} from "fastify";
import {IncomingMessage} from "http";

export const type = 'application/jsoff';

const parser: ContentTypeParser<FastifyRequest<IncomingMessage>> = function (request, done) {
done(null, request.body)
}

export default parser;
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fastify-organizer",
"version": "0.4.1",
"version": "0.5.0",
"description": "Fastify file structure organizer",
"main": "dist/index.js",
"scripts": {
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,11 @@ const fastifyOrganizer: fastify.Plugin<Server, IncomingMessage, ServerResponse,
}
break;
case 'middlewares':
fastify.use(plugin(fastify))
if (plugin.url) {
fastify.use(plugin.url, plugin.default);
} else {
fastify.use(plugin.default);
}
break;
case 'hooks':
fastify.addHook(plugin.event, plugin.default);
@@ -52,11 +56,6 @@ const fastifyOrganizer: fastify.Plugin<Server, IncomingMessage, ServerResponse,
fastify.addContentTypeParser(plugin.type, plugin.opts);
break;
default:
if (plugin.url) {
fastify.use(plugin.url, plugin.default);
} else {
fastify.use(plugin.default);
}
break;
}
}

0 comments on commit d58b796

Please sign in to comment.