TypeScript clarification
See original GitHub issueTl;DR: Can’t get the autoPrefix thing to work with TS files & ts-node.
I’ve tried to use autoPrefix two ways with TypeScript files, and I cannot seem to find a way to it to work as expected.
Things I’ve tried
First Attempt
I tried to add the options.prefix to the Autoload call, like so
// server.ts
import * as Fastify from 'fastify';
import * as Autload from 'autoload';
import { join } from 'path';
const fastify = Fastify();
fastify.register(Autoload, {
dir: join(process.cwd(), 'services'),
includeTypeScript: true,
options: {
prefix: '/api'
}
}
fastify.listen(3000, '0.0.0.0', (err, address)=> {
if(err) {
console.error(err);
process.exit();
}
console.log(`Listening on ${address}`);
})
// services/user.ts
module.exports = (fastify, opts, next)=>{
fastify.get('/user', (req, reply)=> { reply.send('hi'); });
next();
}
This only adds in the /user
route, and not /api/user
Second Attempt
Basically the same server.ts setup, minus the options object.
// services/user.ts
module.exports = (fastify, opts, next) => {
fastify.get('/user', (r, reply)=>{reply.send('hi'); })
next();
}
module.exports.autoPrefix = '/api';
In both cases /api/user
is not found, but /user
is.
Any tips on how to fix this? I’d be happy to submit a pull request for the documentation once I have a solution.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:19 (6 by maintainers)
Top Results From Across the Web
The TypeScript Handbook
The reference section below the handbook in the navigation is built to provide a richer understanding of how a particular part of TypeScript...
Read more >Clarification on Typescript interface when using generics
I want to save datum to another object node and I need to create type definitions for this object node. May I know...
Read more >Clarification of Typescript and JavaScript with respect to the ...
In JavaScript Programming, a Set is an object of distinct keys, and mind you the distinct keys can have the same value as...
Read more >JavaScript/TypeScript: Clarifying Closures - Medium
Closures are nothing more than a fancy term for describing an inherent feature of the JavaScript engine — scope.
Read more >Clarification on typescript optional property : r/typescript - Reddit
Clarification on typescript optional property. As someone who is still learning the language, I need a little clarification for how optional propertys work, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Alright, I’ll look into what can be done to resolve the issue – might take me a bit since I’m swamped with my 9-5 right now, and I’m going to have to look into fastify-plugin to determine what’s going on from that end.
Now we get 404 there