Comments (12)
do you have "routes" directory in "src" ?
from fastify-autoroutes.
can you also provide code how you used fastify-autoroutes
?
from fastify-autoroutes.
do you have "routes" directory in "src" ?
from fastify-autoroutes.
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.
if you cwd is on src, than, 'dir' should be only 'routes'
from fastify-autoroutes.
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.
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.
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.
from fastify-autoroutes.
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.
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)"
from fastify-autoroutes.
I opened a pull request on your repo, hope this help :)
from fastify-autoroutes.
Related Issues (12)
- Stable for use? HOT 2
- [Bug report] dependancies HOT 2
- Support for generics for types in methods. HOT 7
- Don't working ES module type HOT 4
- Support for Fastify 4.0 HOT 3
- Is there a reason why @fastify/error is listed as DevDependency ? HOT 2
- Plugin won't take status.ts as a route HOT 8
- Route conversion HOT 1
- Add "Prefix" feature. HOT 2
- [QUESTION] How to import with ES modules? HOT 4
- subroute multiple keys HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-autoroutes.