client.ts 529 B

123456789101112131415161718192021222324252627282930
  1. const axios = require('axios');
  2. export function getClient(options) {
  3. return axios.create({
  4. baseURL: 'http://localhost:3000',
  5. timeout: 1000,
  6. auth: {
  7. username: options.username,
  8. password: options.password,
  9. },
  10. });
  11. }
  12. export function getAdminClient() {
  13. return getClient({
  14. username: 'admin',
  15. password: 'admin',
  16. });
  17. }
  18. let client = getAdminClient();
  19. client.callAs = function(user) {
  20. return getClient({
  21. username: user.login,
  22. password: 'password',
  23. });
  24. };
  25. export default client;