Similar to this, I am attempting to get the @Headers('origin') property inside a service which does not have its own controller and called to build email links for various other modules. Since the links are shared by email the front end domain triggering the call has to be identified which is done as follows :
import { Headers, Injectable } from '@nestjs/common';
// ... Other code specific imports
@Injectable()
export class LinkService {
constructor(@Headers('origin') private readonly origin: string) {}
createLink1(LinkId1: string): string {
return `${this.origin}/linkpath1/${LinkId1}`;
}
createLink2(LinkId2: string): string {
return `${this.origin}/linkpath2/${LinkId2}`;
}
// ... Similar follows
}
npm start
leads to :
[Nest] 25971 - [ExceptionHandler] Nest can't resolve dependencies of the LinkService (?). Please make sure that the argument String at index [0] is available in the LinkModule context.
Potential solutions:
- If String is a provider, is it part of the current LinkModule?
- If String is exported from a separate @Module, is that module imported within LinkModule?
@Module({
imports: [ /* the Module containing String */ ]
})
+0ms
Error: Nest can't resolve dependencies of the LinkService (?). Please make sure that the argument String at index [0] is available in the LinkModule context.
Potential solutions:
- If String is a provider, is it part of the current LinkModule?
- If String is exported from a separate @Module, is that module imported within LinkModule?
@Module({
imports: [ /* the Module containing String */ ]
})
at Injector.lookupComponentInParentModules (/home/batfan47/graviti/check/graviti-api/node_modules/@nestjs/core/injector/injector.js:188:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Injector.resolveComponentInstance (/home/batfan47/graviti/check/graviti-api/node_modules/@nestjs/core/injector/injector.js:144:33)
at async resolveParam (/home/batfan47/graviti/check/graviti-api/node_modules/@nestjs/core/injector/injector.js:98:38)
Would be great to know what would be the best way to go about this, so that the front end domain is available to me as required even in other parts of the code.