Giter VIP home page Giter VIP logo

Comments (20)

frodoe7 avatar frodoe7 commented on July 17, 2024 1

@mcollina

I fixed it in start.js file by changing that below line (|| instead of &&), however a bit busy to submit PR

-  if (opts.options && file.options) {
+  if (opts.options || file.options) {
     options = deepmerge(options, file.options)
   }

from fastify-cli.

climba03003 avatar climba03003 commented on July 17, 2024 1

You should assign the options to app.options instead of exporting in the end.

from fastify-cli.

climba03003 avatar climba03003 commented on July 17, 2024 1

There is two people checked the library is working correctly. Only you are the person that say it is not working.
Please provide a reproducible repository like what dancastillo did.

@mcollina I would say there is no bug here, may be misconfiguration on author side. However, I don't have permission to this repository. Could you helps to remove both bug and first good issue unless a proper reproducible repository is provided. Thanks.

from fastify-cli.

climba03003 avatar climba03003 commented on July 17, 2024 1

I don't know why you added in dev in first place.
My git diff is showing it should be added in dev:start and start.
Anyway, it works on your side now.

from fastify-cli.

mcollina avatar mcollina commented on July 17, 2024

Thanks for reporting! Fixing this should be easy, it’s likely we are missing some ways to move this option through.

from fastify-cli.

mcollina avatar mcollina commented on July 17, 2024

Would you like to send a PR?

from fastify-cli.

dancastillo avatar dancastillo commented on July 17, 2024

@frodoe7 if you update your script in pacakge.json to include --options should work

    "start": "fastify start -l info app.js --options",
    "dev": "fastify start -w -l info -P app.js --options"
Screenshot 2024-01-01 at 8 59 33 PM

from fastify-cli.

frodoe7 avatar frodoe7 commented on July 17, 2024

@dancastillo and where to add caseSensitive prop?
because I tested also with --options and did not work
the start.js file not pass the options

from fastify-cli.

climba03003 avatar climba03003 commented on July 17, 2024

You should provide the whole index.ts / app.js to show how you export the value.

from fastify-cli.

frodoe7 avatar frodoe7 commented on July 17, 2024

@climba03003
here's the whole app.ts file

import { join } from 'path';
import AutoLoad, {AutoloadPluginOptions} from '@fastify/autoload';
import { FastifyPluginAsync } from 'fastify';

export type AppOptions = {
  // Place your custom options for app below here.
  caseSensitive: boolean
} & Partial<AutoloadPluginOptions>;

// Pass --options via CLI arguments in command to enable these options.
const options: AppOptions = {
    caseSensitive: false,
}

const app: FastifyPluginAsync<AppOptions> = async (
    fastify,
    opts
): Promise<void> => {
  // Place here your custom code!

  // Do not touch the following lines

  // This loads all plugins defined in plugins
  // those should be support plugins that are reused
  // through your application
  void fastify.register(AutoLoad, {
    dir: join(__dirname, 'plugins'),
    options: opts
  });

  // This loads all plugins defined in routes
  // define your routes in one of these
  void fastify.register(AutoLoad, {
    dir: join(__dirname, 'routes'),
    options: opts
  });
};

export default app;
export { app, options }

from fastify-cli.

frodoe7 avatar frodoe7 commented on July 17, 2024

@climba03003

options is not a member of app,

here we talk about the generated template from CLI, not when you use Fastify from scratch

Screenshot 2024-01-02 at 5 02 55 PM

from fastify-cli.

frodoe7 avatar frodoe7 commented on July 17, 2024

@mcollina
Can you look into that PR, should fix that issue?

#691

from fastify-cli.

climba03003 avatar climba03003 commented on July 17, 2024

options is not a member of app,

It is where this library expect the options to be but not FastifyPluginAsync types expect it.
Use @ts-ignore to see what is the outcome.

fastify-cli may not really fit all the expected types on fastify.

here we talk about the generated template from CLI, not when you use Fastify from scratch

No one is talking about using fastify from scratch.

from fastify-cli.

frodoe7 avatar frodoe7 commented on July 17, 2024

@climba03003

Tested with ts-ignore
It's not a fix for the issue

from fastify-cli.

climba03003 avatar climba03003 commented on July 17, 2024

Have you also use the --options flag when starting the application?

Just a git diff to show how it should works.

diff --git a/package.json b/package.json
index ef7aaa1..3cc02c4 100644
--- a/package.json
+++ b/package.json
@@ -8,11 +8,11 @@
   },
   "scripts": {
     "test": "npm run build:ts && tsc -p test/tsconfig.json && c8 node --test -r ts-node/register test/**/*.ts",
-    "start": "npm run build:ts && fastify start -l info dist/app.js",
+    "start": "npm run build:ts && fastify start -l info dist/app.js --options",
     "build:ts": "tsc",
     "watch:ts": "tsc -w",
     "dev": "npm run build:ts && concurrently -k -p \"[{name}]\" -n \"TypeScript,App\" -c \"yellow.bold,cyan.bold\" \"npm:watch:ts\" \"npm:dev:start\"",
-    "dev:start": "fastify start --ignore-watch=.ts$ -w -l info -P dist/app.js"
+    "dev:start": "fastify start --ignore-watch=.ts$ -w -l info -P dist/app.js --options"
   },
   "keywords": [],
   "author": "",
@@ -32,4 +32,4 @@
     "fastify-tsconfig": "^2.0.0",
     "typescript": "^5.2.2"
   }
-}
\ No newline at end of file
+}
diff --git a/src/app.ts b/src/app.ts
index 58aabb6..6ab3b75 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -1,12 +1,13 @@
-import { join } from 'path';
-import AutoLoad, {AutoloadPluginOptions} from '@fastify/autoload';
+import AutoLoad, { AutoloadPluginOptions } from '@fastify/autoload';
 import { FastifyPluginAsync, FastifyServerOptions } from 'fastify';
+import { join } from 'path';

 export interface AppOptions extends FastifyServerOptions, Partial<AutoloadPluginOptions> {

 }
 // Pass --options via CLI arguments in command to enable these options.
 const options: AppOptions = {
+  caseSensitive: false
 }

 const app: FastifyPluginAsync<AppOptions> = async (
@@ -35,4 +36,5 @@ const app: FastifyPluginAsync<AppOptions> = async (
 };

 export default app;
-export { app, options }
+export { app, options };

from fastify-cli.

frodoe7 avatar frodoe7 commented on July 17, 2024

@climba03003 Still not works and not a solution, did you test that solution by yourself?

from fastify-cli.

dancastillo avatar dancastillo commented on July 17, 2024

@frodoe7 here is demo repo with working example. Specific changes were in this commit

from fastify-cli.

frodoe7 avatar frodoe7 commented on July 17, 2024

@climba03003 really? Okay

It's still not working with your suggestion, it worked only when I implemented that change #687 (comment)

anyway, I used patch-package to apply that change, in case no intention to fix it

from fastify-cli.

climba03003 avatar climba03003 commented on July 17, 2024

It's still not working with your suggestion

Just saying it is not working do not helps to move thing forward.
Providing a reproducible repository is what we would like to see and investigate.

from fastify-cli.

frodoe7 avatar frodoe7 commented on July 17, 2024

@climba03003

It worked when I added --options in dev:start instead of dev
in package.json

from fastify-cli.

Related Issues (20)

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.