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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@attachments/proxy

v0.4.0

Published

proxy server for front-end developers

Downloads

43

Readme

@attachments/proxy

为前端开发者准备的代理服务器

快速开始

安装并配置浏览器插件

SwitchyOmega 是一个知名的浏览器代理工具,它可以将浏览器的 http 请求全部重定向到你本地的代理工具上(只负责请求重定向,其本身没有代理功能)。

下载地址 (GitHub Release)

插件安装完成之后,打开设置页面,新建情景模式,按照如下的方法配置,确认无误后保存,不代理的地址列表保持默认即可:

插件使用

安装依赖

yarn add @attachments/proxy

# or npm install @attachments/proxy

编写规则

在工作目录下新建一个 proxy.js 文件(名称随意),使用下面的代码:

import { ProxyServer } from '@attachments/proxy';

async function runApp() {
  const server = new ProxyServer();
  server.addRule(
    'proxy.yuzzl.top',
    {
      location: '/',
      // 当访问 proxy.yuzzl.top 时,代理到 http://localhost:8001
      proxyPass: 'http://localhost:8001',
    },
    {
      // 当访问 proxy.yuzzl.top/hello/world/xxx 时,代理到 http://localhost:8001/hello_world/xxx
      location: '/hello/world',
      proxyPass: 'http://localhost:8001/hello_world',
    },
  );

  await server.initServers();
  await server.listen();
}

runApp().catch(e => {
  console.log(e);
});

启动项目

node proxy.js

接下来:

  • 当你访问 proxy.yuzzl.top,会将请求代理到 http://localhost:8001

  • 当你访问 proxy.yuzzl.top/hello/world/xxx,会将请求代理到 http://localhost:8001/hello_world/xxx

常见问题

HTTPS 环境下浏览器提示不安全

proxy 内置了一个根证书,位于 package 的 certificate 目录下,你需要让你的计算机信任 rootCA.pem

macOS 系统

  • 请在 Finder 中打开该目录,可以进入 node_modules 找到它。

image

  • 双击 rootCA.pem,将证书导入到钥匙串,如图所示:

image

  • 双击该证书,打开信任选项,设置为始终信任。

image

window 系统

本人无 window 电脑,待补充...

它是如何工作的?

请参考《HTTP 权威指南》的如下内容:

  • 第十四章第九节:通过代理以隧道形式传输安全流量
  • 中间人攻击
  • 第六章:代理

具体实现原理不久我会写一篇文章来讲解