Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
TakNePoidet committed Jun 27, 2021
0 parents commit 01eb35c
Show file tree
Hide file tree
Showing 20 changed files with 44,357 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
indent_style = tab
indent_size = 2
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true

[*.{md,txt}]
indent_size = 2
indent_style = space
end_of_line = LF

trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
tsconfig.json
coverage
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
extends: ['@taknepoidet-config/eslint-config'],
rules: {
'import/no-dynamic-require': 0,
'@typescript-eslint/no-var-requires': 0,
'import/no-extraneous-dependencies': 0
},
overrides: [
{
files: ['*.spec.ts'],
plugins: ['jest'],
rules: {
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'warn',
'jest/valid-expect': 'error'
},
env: {
'jest/globals': true
}
}
]
};
81 changes: 81 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Common settings that generally should always be used with your language specific settings

# Auto detect text files and perform LF normalization
# https://www.davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/
* text=lf

#
# The above will handle all files NOT found below
#

# Documents
*.bibtex text diff=bibtex
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
*.md text diff=markdown
*.tex text diff=tex
*.adoc text
*.textile text
*.mustache text
*.csv text
*.tab text
*.tsv text
*.txt text
*.sql text
*.ps1 text eol=crlf

# Graphics
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.tif binary
*.tiff binary
*.ico binary
# SVG treated as an asset (binary) by default.
*.svg text
# If you want to treat it as binary,
# use the following line instead.
# *.svg binary
*.eps binary

# Scripts
*.bash text eol=lf
*.fish text eol=lf
*.sh text eol=lf
# These are explicitly windows files and should use crlf
*.bat text eol=crlf
*.cmd text eol=crlf

# Serialisation
*.json text
*.toml text
*.xml text
*.yaml text
*.yml text

# Archives
*.7z binary
*.gz binary
*.tar binary
*.tgz binary
*.zip binary

# Text files where line endings should be preserved
*.patch -text

#
# Exclude files from exporting
#

.gitattributes export-ignore
.gitignore export-ignore
.gitkeep export-ignore
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
node_modules
*.log
coverage
.idea
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/**
dist
*.md
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('@taknepoidet-config/prettier')
};
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# fastify-route-group

Grouping and inheritance of routes

## Installation

```bash
npm i fastify-route-group
```

or

```
yarn add fastify-route-group
```

## Usage

```javascript
const fastify = require('fastify');

async function bootstrap() {
const server = fastify();
const router = new Router(server);

router.get('/', (_, reply) => {
reply.send('index page');
});

router.namespace('api', () => {
router.namespace('methods', () => {
router.prefix('posts.', () => {
router.get('get', (_, reply) => {
reply.send('get posts from API');
});
});
router.prefix('users.', () => {
router.get('get', (_, reply) => {
reply.send('get users from API');
});
});
});
});
}

bootstrap()
.then();
```

The following routes are obtained

| Url | Description |
| ---------------------- | ----------- |
| / | index page |
| /api/methods/posts.get | posts api |
| /api/methods/users.get | users api |
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript']
};
48 changes: 48 additions & 0 deletions example/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import fastify, { RouteOptions } from 'fastify';
import { Router } from '../dist';

async function bootstrap() {
const server = fastify();

server.addHook('onRoute', (route: RouteOptions) => {
console.log(route);
});
server.addHook('onReady', () => {
console.log('onReady');
});
const router = new Router(server);

router.get('/', (_, reply) => {
reply.send('index');
});
router.post('/', (_, reply) => {
reply.send(' post index');
});

function api() {
router.namespace('methods', () => {
router.prefix('posts.', () => {
router.get('get', (_, reply) => {
reply.send('api get posts');
});
});
router.prefix('photos.', () => {
router.get('get', (_, reply) => {
reply.send('api get photos');
});
});
});
}
router.namespace('api', () => {
api();
});
console.log(router);
await server.listen(3000, (err, address) => {
if (err) {
throw err;
}
console.log(`Открыть адрес ${address}`);
});
}

bootstrap().then();
Loading

0 comments on commit 01eb35c

Please sign in to comment.