npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vite-plugin-api-encrypt

v1.1.1

Published

Vite plugin to encrypt API paths and enhance API security

Readme

vite-plugin-api-encrypt

Vite 插件,用于加密项目中的 API 路径,增加 API 调用的安全性。此版本为 JavaScript 实现。

功能

  • 自动加密代码中的 API 路径字符串
  • 支持自定义加密密钥
  • 通过 src 方式注入解密函数到 HTML 中
  • 支持多种 API 路径格式匹配

安装

pnpm install vite-plugin-api-encrypt --save-dev
# 或
yarn add vite-plugin-api-encrypt -D

使用方法

  1. vite.config.jsvite.config.ts中引入插件:
// vite.config.js
import { defineConfig } from "vite";
import apiEncrypt from "vite-plugin-api-encrypt";

export default defineConfig({
  plugins: [
    apiEncrypt({
      // 配置选项
      key: "your-secret-key", // 加密密钥
      decryptName: "__decryptApi", // 全局解密函数名
      apiPrefixes: "sys|api", // 匹配的API路径前缀,不需要包含前导斜杠
    }),
  ],
});
  1. 在代码中使用 API 路径:
// 原始代码
fetch("/sys/user/list");

// 插件处理后(运行时会自动解密)
fetch(__decryptApi("encrypted-string"));

配置选项

| 选项 | 类型 | 默认值 | 说明 | | ----------- | ------ | ---------------- | --------------------------------- | --------------------------------------------- | | key | string | 'api-encode-key' | 加密密钥,用于加密和解密 API 路径 | | decryptName | string | '__decryptApi' | 全局解密函数名 | | apiPrefixes | string | 'sys | api' | 要匹配的 API 路径前缀数组,不需要包含前导斜杠 |

支持的 API 路径格式

插件会自动匹配以下格式的 API 路径:

  • /sys/xxx
  • /api/xxx

注意事项

  1. 确保加密密钥在开发环境和生产环境中保持一致
  2. 本插件仅提供基本的 XOR 加密,对于高安全性需求,建议使用更复杂的加密算法
  3. 加密仅应用于字符串字面量,不会影响动态生成的 API 路径
  4. 插件会自动创建一个名为api-decrypt.js的解密函数文件,并通过 src 方式注入到 HTML 中
  5. 开发服务器会自动处理解密函数文件的请求,无需手动创建该文件