proxy.ts 723 B

1234567891011121314151617181920212223242526272829303132333435
  1. const proxyTableList = [
  2. 'cli',
  3. 'v1',
  4. 'v2',
  5. 'auth',
  6. 'v1-openai',
  7. 'version',
  8. 'proxy',
  9. 'update',
  10. 'grafana'
  11. ];
  12. // @ts-ingore
  13. export default function createProxyTable(target?: string) {
  14. const proxyTable = proxyTableList.reduce(
  15. (obj: Record<string, object>, api) => {
  16. const newTarget = target || 'http://localhost';
  17. obj[`/${api}`] = {
  18. target: newTarget,
  19. changeOrigin: true,
  20. secure: false,
  21. ws: true,
  22. log: 'debug',
  23. pathRewrite: (pth: string) => pth.replace(`/^/${api}`, `/${api}`),
  24. headers: {
  25. origin: newTarget,
  26. Connection: 'keep-alive'
  27. }
  28. };
  29. return obj;
  30. },
  31. {}
  32. );
  33. return proxyTable;
  34. }