Code Monkey home page Code Monkey logo

Comments (12)

GiovanniCardamone avatar GiovanniCardamone commented on June 12, 2024

do you have "routes" directory in "src" ?

from fastify-autoroutes.

GiovanniCardamone avatar GiovanniCardamone commented on June 12, 2024

can you also provide code how you used fastify-autoroutes?

from fastify-autoroutes.

karmabadger avatar karmabadger commented on June 12, 2024

do you have "routes" directory in "src" ?

image

from fastify-autoroutes.

karmabadger avatar karmabadger commented on June 12, 2024

can you also provide code how you used fastify-autoroutes?
index.ts:

import fastify, { FastifyInstance } from "fastify";
import * as autoroutes from "fastify-autoroutes";

const app: FastifyInstance = fastify({ logger: true });

const startServer = async () => {
  await app.register(autoroutes.default, {
    dir: "./src/routes",
    prefix: "/api/v1", // -> optional
  });

  await app.listen(3000);
};

startServer();

src/routes/some.ts:

import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
import { Resource } from 'fastify-autoroutes'

export default (fastify: FastifyInstance) => <Resource> {
  get: {
    handler: async (request: FastifyRequest, reply: FastifyReply) => 'Hello, Route!'
  }
}

from fastify-autoroutes.

GiovanniCardamone avatar GiovanniCardamone commented on June 12, 2024

if you cwd is on src, than, 'dir' should be only 'routes'

from fastify-autoroutes.

karmabadger avatar karmabadger commented on June 12, 2024

if you cwd is on src, than, 'dir' should be only 'routes'
no I'm running index.ts from the root dir whcih is not in src.
is it better to have it all in src instead?

from fastify-autoroutes.

GiovanniCardamone avatar GiovanniCardamone commented on June 12, 2024

your index.ts should be in "src" folder (usually this is the way is done) than you have to run the program using "src" (or dist, if it's builded) as cwd

example:
...
"scripts": {
"start": "node dist",
"dev": "ts-node-dev src"
}

in this case, if you use "routes", the plugin will know he have to take from "<your folder location>/src" (or dist if is builded)

from fastify-autoroutes.

karmabadger avatar karmabadger commented on June 12, 2024

your index.ts should be in "src" folder (usually this is the way is done) than you have to run the program using "src" (or dist, if it's builded) as cwd

example: ... "scripts": { "start": "node dist", "dev": "ts-node-dev src" }

in this case, if you use "routes", the plugin will know he have to take from "<your folder location>/src" (or dist if is builded)

whether it is in src shouldn't really matter right? it's just mostly depending on how the devs are used to?

from fastify-autoroutes.

karmabadger avatar karmabadger commented on June 12, 2024

I'm going to try it anyways
image

from fastify-autoroutes.

karmabadger avatar karmabadger commented on June 12, 2024
ts-node src/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\src\index.ts\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)

from fastify-autoroutes.

GiovanniCardamone avatar GiovanniCardamone commented on June 12, 2024

ts-node src

if you start with ts-node src/index.ts the cwd is not setted to 'src', so the routes should be "../routes".

Usually, if you are not running a script, you run a module by the index file (so just "node dist (or ts-node src in your case)"

Screenshot_20_04_2022-08_44_07

from fastify-autoroutes.

GiovanniCardamone avatar GiovanniCardamone commented on June 12, 2024

I opened a pull request on your repo, hope this help :)

from fastify-autoroutes.

Related Issues (12)

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.