@flaregun-net/proxyflare-for-pages

中文文档
0.1.0发布于 2023/01/31MITTypeScriptCommonJS零依赖近 30 天下载 3207

A reverse proxy for your website on Cloudflare Pages

原始使用文档
文档目录12 节
  1. Overview
  2. Use cases
  3. Proxy traffic to another service
  4. Mount a hosted website on your domain
  5. Redirect traffic from one place to another
  6. Serve static content through Proxyflare
  7. Install
  8. Plug in
  9. Scaffold
  10. Configure
  11. Deploy
  12. Next steps

Proxyflare for Cloudflare Pages

Visit our website for the full documentation.

Overview

Proxyflare is a reverse proxy that makes it easy to move HTTP traffic around your domain and across the internet.

This package provides Proxyflare as a Cloudflare Pages plugin. Any website deployed on Cloudflare Pages may use Proxyflare.

Proxyflare is a middleware layer that matches incoming requests to Routes in your Configuration.

Refer to the Cloudflare documentation for more information about Pages Middleware, Pages Functions and other awesome community Plugins that can enhance your website.

Use cases

Proxy traffic to another service

Proxy traffic from a part of your domain to another service on the same domain or elsewhere on the internet

Examples

  1. Move traffic from https://yoursite.com/api/* to https://your-hosted-api.com
  2. Host a service on https://torrents.yoursite.com/* that points to http://yoursite.com:41321

Notes

  • Proxyflare works over http(s): and ws(s): (websockets)
  • A proxied service must be available on the public internet
  • Both standard and custom ports are supported (e.g. 80, 443, 8787, etc.)

Learn more

Mount a hosted website on your domain

Examples

  1. Mount your React-powered documentation hosted at https://hosted-docs.com on https://yoursite.com/docs/*
  2. Mount a WordPress site hosted at https://some-wordpress-blog.com on https://yoursite.com/blog/*

Notes

  • Mounted websites should configure the base url to match its mounted pathname
  • Static resources such as stylesheets must be carefully added to Route["to.website.resources"]

Learn more

Redirect traffic from one place to another

  1. Version an API (e.g. redirect /v2/api)
  2. Redirect stale content URLs

Notes

  • Redirects are wildcard-compatible
  • Any 300-level status code is supported

Learn more

Serve static content through Proxyflare

  1. Publish unique robots.txt and other website metadata files around your domain

Notes

  • Custom response headers are supported to set Content-Type for text, JSON, or others
  • Text files should be no larger than 16KB

Learn more

Install

Install @flaregun-net/proxyflare-for-pages and @cloudflare/workers-types using your preferred Node.js package manager

npm install @flaregun-net/proxyflare-for-pages
npm install -D @cloudflare/workers-types

Plug in

Scaffold

In your Cloudflare Pages project, create a functions/_middleware.ts file. The name of this file must be exactly as written because Cloudflare Pages uses the file name internally for routing. If your project already has a functions/_middleware.ts that exports a single onRequest object, convert it to a list of middleware for convenience. Middleware is called in the order listed.

The onRequest middlewares should include the following configuration. Notice that we wrap Proxyflare in a PagesFunction in order to use environment variables with Proxyflare. Learn more about environment variables and secrets.

import proxyflare from "@flaregun-net/proxyflare-for-pages"

const routes: Route[] = []

// `PagesFunction` is from @cloudflare/workers-types
export const onRequest: PagesFunction[] = [
  (context) =>
    proxyflare({
      config: {
        global: { debug: true },
        routes,
      },
    })(context),
  // other Pages plugins and middleware
]

This is a barebones Proxyflare configuration with debug enabled that will help with set up and configuration. Learn more about debugging Proxyflare.

Configure

Next, you'll need to write your first Route. Check out the use cases section to find Route ideas. If you don't have one yet, try this example:

const routes: Route[] = [
  {
    from: {
      pattern: "yourdomain.com/proxyflare-example",
      alsoMatchWWWSubdomain: true,
    },
    to: { url: "https://example.com" },
  },
]

Replace yoursite.com with your domain name.

Deploy

Once you have a Route set up, deploy a new version of your Cloudflare Pages website, and keep an eye on the deployment. Once the deployment is successful, navigate to your domain.

For the example Route above, you should see https://example.com rendered at yourdomain.com/proxyflare-example. If you don't see it, refer to the debugging Proxyflare section or reach out for help in Discord.

Next steps

Now that you're up and running, check out the Tutorials to learn more about what you can do with Proxyflare.

版本与发布记录

@flaregun-net/proxyflare-for-pages 共发布 4 个版本,首次发布于 2022/12/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.0latest2023/01/313 年前
0.0.2232023/01/193 年前
0.0.2192023/01/183 年前
0.0.220-beta.02022/12/223 年前

关于 @flaregun-net/proxyflare-for-pages 的常见问题

@flaregun-net/proxyflare-for-pages 是什么?

A reverse proxy for your website on Cloudflare Pages

如何安装 @flaregun-net/proxyflare-for-pages?

在项目目录运行 npm install @flaregun-net/proxyflare-for-pages,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@cloudflare/workers-types(3.14.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flaregun-net/proxyflare-for-pages 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flaregun-net/proxyflare-for-pages 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@flaregun-net/proxyflare-for-pages 可以商用吗?

@flaregun-net/proxyflare-for-pages 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flaregun-net/proxyflare-for-pages 的下载量有多少?

根据 npm 官方下载统计,@flaregun-net/proxyflare-for-pages 在 2026/10/15 – 2026/11/13 这 30 天内被下载 3,207 次,日均约 107 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flaregun-net/proxyflare-for-pages 还在维护吗?

最新版本 0.1.0 发布于 2023/01/31(3 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/12/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。