New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

vite-plugin-interceptor

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-interceptor

A vite plugin based on service worker to intercept and modify requests in a development environment

latest
Source
npmnpm
Version
1.0.4
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-interceptor

English | 中文

A vite plugin based on service worker to intercept and modify requests in a development environment

the browser needs to support service worker

a chrome extension can be used in production environment. easy-interceptor

Usage

npm i -D vite-plugin-interceptor

// in vite.config.ts


import interceptor from 'vite-plugin-interceptor'

export default defineConfig({
    plugins: [
        // interceptor()
        // or
        interceptor({
            input: 'src/index.ts', // default src/main.ts
            mockDir: '__mock__',   // default mock
        }),
    ]
})

// create a .ts or .js file in __mock__ dir, must use export default and set rules by plugin provide

export default function() {
    window.__INTERCEPTOR_DEVTOOL__.set(
        '1',
        {
            url: '**/tsconfig.json',
            method: 'get',
            response: '{"foo":"test"}',
            // enable: false,
            // delay: 5000,
        }
    )
}

ts type, create a file interceptor.d.ts, input this text

/// <reference types="vite-plugin-interceptor/typing" />

API

__INTERCEPTOR_DEVTOOL__

propexplaintypedescription
getget rules()=>Promise
setset a rule(id, rule) => void
clearclear all rules()=>void

InterceptorRule

propexplaintypedescription
urlmatch request urlstringrequired
responseresponse textstringrequired
delaydelaynumber0
enableenable rulebooleantrue
methodrequest methodget post put delete
responseHeadersresponse headersRecord<string, string>{}
statusresponse statusnumber200

perhaps, it has a warn in vite2.0, you can use as any as Plugin to resolve it.

about multi-page: the sw.js scope is ./, so the plugin supports multi-page. just load the configured page to make the script active

LICENSE

MIT

Keywords

vite

FAQs

Package last updated on 31 Aug 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