import { PROXY_TYPE } from './types';
import fs from 'fs-extra';
import path from 'path';
import { createProxy, ProxyList } from '../../build/vite/proxy';

export const createProxyList = (devProxy: PROXY_TYPE) =>
  [
    ['/ws_api_bak/', devProxy.serverHost],
    ['/safety_api/', devProxy.serverHost],
  ] as ProxyList;

export const createConfig = (appConfigPath: string) => {
  // 将app.config.js复制到public目录下
  fs.copy(appConfigPath, path.resolve(process.cwd(), 'public/app.config.js'));
};

export const start = (proxy: PROXY_TYPE, appConfigPath: string) => {
  // 将app.config.js
  createConfig(appConfigPath);
  return createProxy(createProxyList(proxy));
};
