I have problem , I implimented the proxy in my Angular 15.0 project, but 
want to add auth token in it with dynamic way , I have also did a work 
around, but not able to succeed All files are located src level at ng serve 
time , project giveing me thr error : An unhandled exception occurred: 
Cannot find module './config'

this error located in proxy.conf.js line :  const { authConfig } = require(
'./config');

Here is my
This is the session service:
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class SessionStorageService {
  setItem(key: string, value: any) {
    sessionStorage.setItem(key, JSON.stringify(value?.access_token));
  }

  getItem(key?: string): any {
    const item = sessionStorage.getItem(key);
    return item ? JSON.parse(item) : null;
  }
}

and this the congif file:

import { SessionStorageService } from './session.service';

const authConfigService = new SessionStorageService();
const authToken = authConfigService.getItem();
console.log(authToken);
export const authConfig = {
  authToken: authToken
};
and finally here is proxy.conf.js
const { authConfig } = require('./config');

var defaultTarget = 'https://example.com/';
module.exports = [
  {
    context: ['/v1/**'],
    target: defaultTarget,
    changeOrigin: true,
    headers: { "Authorization": `Bearer ${authConfig.authToken}` }
  }
];

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/angular/70809282-8196-4614-9e9c-949ee8d661c4n%40googlegroups.com.

Reply via email to