Socket
Book a DemoInstallSign in
Socket

miragejs-axios-adapter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

miragejs-axios-adapter

miragejs axios adapter

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

Miragejs axios adapter

Installation

yarn add miragejs-axios-adapter
# OR
npm i miragejs-axios-adapter

Usage

import useAdapter from 'miragejs-axios-adapter';
import axios from 'axios';
import { createServer } from 'miragejs';

const NAMESPACE = '/api/mock';
const MOCK_API_REGEX = /^\/api\/mock/;
const PROXY_API_REGEX = /^\/(api)\//;

function mockServer() {
  useAdapter(axios, MOCK_API_REGEX);

  const server = createServer({
    routes() {
      this.namespace = NAMESPACE;

      // More apis
    }
  });

  server.passthrough(
    ({ url }) => PROXY_API_REGEX.test(url) && !MOCK_API_REGEX.test(url)
  );

  return server;
}

if (process.env.NODE_ENV === 'development') {
  mockServer();
}

FAQs

Package last updated on 31 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts