Git Product home page Git Product logo

fastify-autoroutes's Introduction

Hi there ๐Ÿ‘‹ I'm Giovanni!

I'm a Software Developer ๐Ÿˆ

  • ๐ŸŒฑ Iโ€™m currently learning Rust, 3D, AI
  • ๐Ÿ“ฌ You can reach me on My Website
  • โšก Fun fact: I only use linux distro's
  • ๐Ÿฅ… 2023 Goals: Contribute more to Open Source projects

Connect With Me

Giovanni Cardamone | Website Giovanni Cardamone | LinkedIn Giovanni Cardamone | Instagram Giovanni Cardamone | LinkedIn Giovanni Cardamone | LinkedIn

Followers Stars Profile views

GitHub Stats Top Languages

code

fastify-autoroutes's People

Contributors

allcontributors[bot] avatar azrikahar avatar dependabot-preview[bot] avatar dependabot[bot] avatar genbs avatar giovannicardamone avatar rcoopr avatar tronikelis avatar wilbert-abreu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fastify-autoroutes's Issues

Add "Prefix" feature.

Feature description

"Prefix" feature, allow a base such as "/api" without nesting all routes in the /routes/api folder

Feature motivation

ease of use, similar to nextjs.

Implementation:

app.register(fastifyAutoRoutes, {
    dir: path.join(staticPath, 'routes'),
    ignorePattern: /.*\.test\.js/,
    prefix: "/api/"
});

Support for generics for types in methods.

Feature description

Support for generics for types in methods.
Something similar to what fastify already has for their method routes.
for instances:

server.get<{
    Querystring: IQuerystring;
    Headers: IHeaders;
    Reply: ReplyBodyType;
  }>(fullpath, async (request, reply) => {
    console.log("name");
    reply.status(200).send({ success: true, message: "hello world" });
  });

This types all of the querystring, headers, and reply using a very nice and simple and neat syntax.

Feature motivation

Typing is quite neat and useful in TS. And this way and syntax is also very nice.
Thanks

Don't working ES module type

Versions

fastify-autoroute: 2.1.3
node: 18.1.0
os: docker [Alpine]
terminal: sh

Expected Behavior

Working autorouting

Actual Behavior

Not working everything

Steps to Reproduce

import fastifyFramework from 'fastify';
import fastifyAutoRoutes from 'fastify-autoroutes'
import fastifyStatic from "@fastify/static";
import fastifyCors from '@fastify/cors';
import path from 'path';
import {dirname} from 'path';
import {fileURLToPath} from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));

const fastify = fastifyFramework({
	logger: process.env.ENVIRONMENT !== 'production',
});

fastify.register(fastifyAutoRoutes, {
	dir: '../src/routes',
});

fastify.register(fastifyCors, {
	origin: true,
	credentials: true
});

fastify.register(fastifyStatic, {
	root: path.join(__dirname, 'public'),
	prefix: '/public/'
});

const start = async () => {
	try {
		await fastify.listen(80, '0.0.0.0');
	} catch (e) {
		fastify.log.error(e);
		setTimeout(start, 5000);
	}
}
await start();
{
  "name": "deal",
  "version": "0.0.1",
  "type": "module",
  "scripts": {
    "dev": "nodemon index.js",
    "start": "node index.js"
  },
  "dependencies": {
    "@fastify/cors": "^7.0.0",
    "@fastify/static": "^5.0.2",
    "fastify": "^3.29.0",
    "fastify-autoroutes": "^2.1.3"
  }
}

SCREENSHOT ERROR

image

Support for Fastify 4.0

Currently, you cannot install along Fastify 4.0, dependency resolution fails. Can we have support for Fastify 4.0?

[QUESTION] How to import with ES modules?

I can seem to get the package working correctly when using ES modules:

server.js:

...
import autoroutes from 'fastify-autoroutes'
...
...
  try {
    await server.register(autoroutes, {
      dir:'./routes',
    })
  } catch (error) {
    console.log('ERROR:', error)
  }
...

When the server is started, the following exception:
"Error [ERR_REQUIRE_ESM]: require() of ES Module .../src/routes/index.js from .../node_modules/fastify-autoroutes/dist/index.js not supported"

subroute multiple keys

Feature description

Route directories when they contain a :key path ignore all others in the directory.
I'm hoping for support for something like this, this is just an example.

/users/
/users/{uuid}/
/users/create/

users/create isn't available because it'd be passed to users/{uuid}.

Feature motivation

More complex and detailed API structures.

Bug Report: Windows fileystem issue

Versions

  • Node Version: v16.14.2
  • Operating System: Windows 10
  • Terminal: Windows Powershell

Behavior

from this repo: https://github.com/karmabadger/fastify-routes-test

when running:
npm run dev

> [email protected] dev
> nodemon index.ts

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: ts,json
[nodemon] starting `ts-node index.ts`
C:\Users\wenxu\Projects\test\fileroutes\node_modules\fastify-autoroutes\dist\index.js:4
    return new (P || (P = Promise))(function (resolve, reject) {
           ^
Error: fastify-autoroutes dir C:\Users\wenxu\Projects\test\fileroutes\index.ts\src\routes does not exists
    at C:\Users\wenxu\Projects\test\fileroutes\node_modules\fastify-autoroutes\src\index.ts:116:19
    at Generator.next (<anonymous>)
    at C:\Users\wenxu\Projects\test\fileroutes\node_modules\fastify-autoroutes\dist\index.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Users\wenxu\Projects\test\fileroutes\node_modules\fastify-autoroutes\dist\index.js:4:12)
    at exports.default.fastify_plugin_1.default.fastify (C:\Users\wenxu\Projects\test\fileroutes\node_modules\fastify-autoroutes\src\index.ts:98:7)
    at Plugin.exec (C:\Users\wenxu\Projects\test\fileroutes\node_modules\avvio\plugin.js:132:19)
    at Boot.loadPlugin (C:\Users\wenxu\Projects\test\fileroutes\node_modules\avvio\plugin.js:274:10)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
[nodemon] app crashed - waiting for file changes before starting...

when running:

npm run start```

[email protected] start
node ./build/index.js

C:\Users\wenxu\Projects\test\fileroutes\node_modules\fastify-autoroutes\dist\index.js:44
return next(new Error(${exports.ERROR_LABEL} dir ${dirPath} does not exists));
^

Error: fastify-autoroutes dir C:\Users\wenxu\Projects\test\fileroutes\build\index.js\src\routes does not exists
at C:\Users\wenxu\Projects\test\fileroutes\node_modules\fastify-autoroutes\dist\index.js:44:21
at Generator.next ()
at C:\Users\wenxu\Projects\test\fileroutes\node_modules\fastify-autoroutes\dist\index.js:8:71
at new Promise ()
at __awaiter (C:\Users\wenxu\Projects\test\fileroutes\node_modules\fastify-autoroutes\dist\index.js:4:12)
at exports.default.fastify_plugin_1.default.fastify (C:\Users\wenxu\Projects\test\fileroutes\node_modules\fastify-autoroutes\dist\index.js:31:72)
at Plugin.exec (C:\Users\wenxu\Projects\test\fileroutes\node_modules\avvio\plugin.js:132:19)
at Boot.loadPlugin (C:\Users\wenxu\Projects\test\fileroutes\node_modules\avvio\plugin.js:274:10)
at processTicksAndRejections (node:internal/process/task_queues:83:21)

Am I doing this correctly? Perhaps I'm missing something? 
I feel like on windows only, it's not resolving the paths to each of the routes correctly when it's doing the dynamic routes imports.   ```C:\Users\wenxu\Projects\test\fileroutes\index.ts\src\routes does not exists.``` as we can see here, it's getting the absolute path to the file not the directly which causes issues here. 
I know that the node module filesystem will also complain if ```file://``` isn't prepended at the beginning to tell it the protocol if it's an absolute file path (at least I think that could be an issue)).

Does this issue even occur on linux or mac? 
If only on windows I could try to figure out what's wrong and make a PR, tho I'm a bit new to the Open source dev scene so Ill have to figure out how it works haha.

Thanks

[Bug report] dependancies

Hello,

I have just installed fast-autoroutes in a new project but the post installation (using npm) displays:

> npm install --save fastify-autoroutes

added 16 packages, and audited 921 packages in 2s

52 packages are looking for funding
  run `npm fund` for details

7 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
> npm audit

# npm audit report

ansi-regex  >2.1.1 <5.0.1
Severity: moderate
 Inefficient Regular Expression Complexity in chalk/ansi-regex - https://github.com/advisories/GHSA-93q8-gq69-wqmw
fix available via `npm audit fix --force`
Will install [email protected], which is a breaking change
node_modules/fastify-autoroutes/node_modules/ansi-regex
  strip-ansi  4.0.0 - 5.2.0
  Depends on vulnerable versions of ansi-regex
  node_modules/fastify-autoroutes/node_modules/strip-ansi
    cliui  4.0.0 - 5.0.0
    Depends on vulnerable versions of strip-ansi
    Depends on vulnerable versions of wrap-ansi
    node_modules/fastify-autoroutes/node_modules/cliui
      yargs  10.1.0 - 15.0.0
      Depends on vulnerable versions of cliui
      Depends on vulnerable versions of string-width
      node_modules/fastify-autoroutes/node_modules/yargs
        fastify-autoroutes  >=2.0.0
        Depends on vulnerable versions of yargs
        node_modules/fastify-autoroutes
    string-width  2.1.0 - 4.1.0
    Depends on vulnerable versions of strip-ansi
    node_modules/fastify-autoroutes/node_modules/string-width
      wrap-ansi  3.0.0 - 6.1.0
      Depends on vulnerable versions of string-width
      Depends on vulnerable versions of strip-ansi
      node_modules/fastify-autoroutes/node_modules/wrap-ansi

7 moderate severity vulnerabilities

It seems you have an unused dependencies in package.json: json5, pluralize and yargs.

You could probably cleanup the dev dependancies as well.

Also note that the npm package contains unrelated (old) files in the dist/ folder.

Plugin won't take status.ts as a route

Versions

  • Node Version: v18.12.1
  • Operating System: Ubuntu
  • Terminal: Vscode terminal

Expected Behavior

List all the routes in the subdir

Actual Behavior

The route is missing from the list of available routes

Steps to Reproduce

I just added a new file to the directory with the same content as health.ts

Screenshots (Optional)

Screenshot 2022-11-18 at 10 18 38 AM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.