惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
Y
Y Combinator Blog
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Check Point Blog
M
MIT News - Artificial intelligence
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
F
Fortinet All Blogs
博客园 - 司徒正美
I
InfoQ
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
U
Unit 42

少数派

派早报:Google 发布 Fitbit Air 等 - 少数派 「新人报到」確認需求,再開始 - 少数派 从 SOLO 独立开发者社区,我看到了越来越多开发者开始做自己的产品 - 少数派 我怎么管理那些"不常做,但总会忘"的生活事项 - 少数派 人形机器人量产元年,数据才是具身智能的“生死线” - 少数派 BuhoLaunchpad 高度还原 Mac 启动台:开发历程与思考 - 少数派 五年陪伴依然不舍,DIY 换壳后让罗技 MX Master 3 继续服役 - 少数派 新玩意 240|少数派的编辑们最近买了啥? - 少数派 一日一技|为什么你应该关闭 iOS 的键盘声音 - 少数派 我做了个插件和 Skills,一键提取任何网站的设计规范 Design.md - 少数派 住在三四线城市的你,该开始录播客了 - 少数派 甘南秘境,大白高国 - 少数派 AI的审美:谁让把我变成川内倫子 - 少数派 返工怎能不烦恼,打工人片单总有一部是你的「嘴替」 - 少数派 为了让「上厕所」更健康,我做了一个小工具 - 少数派 AI + Skill,能够让生成的文章去除 AI 味吗? - 少数派 新玩意|韶音OpenDots ONE 耳夹式耳机 - 少数派 《美满》| 在每一个春天的晚上相爱(362) - 少数派 新玩意|优篮子 PS01 MagSnap 磁吸支架 - 少数派 自我整合手记 | 我开始早睡了:用稳定规则,为自由托底 - 少数派 用龙虾(OpenClaw)两个多月,我最深的12个体会 - 少数派 听歌时间到,12 张你可能错过的 2025 华语乐坛好专辑 - 少数派 承诺能追吗 - 少数派 macOS 26启动台没了? 我做了个不一样的App启动器 - Keboard - 少数派 《四海为家的人》| INTJ对话INTJ(361) - 少数派 你发过的那些黑历史,是时候一次清干净了 - 少数派 新玩意:安安静静玩,越玩越专注:计客密码机 - 少数派 iPad 用户首次体验 Android 平板:vivo Pad6 Pro - 少数派 数据逻辑强 - 少数派 极北行+ | 一路向北,探访日本至北之地 | 001 - 少数派
Notion绑定域名-你的笔记就是你的博客! - 少数派
2021-07-22 · via 少数派

为Notion公共页面提供自定义域名可能是最受要求的功能之一,而且目前看起来还不支持这样做(可以理解)但是,这里有一个使用Cloudflare Workers的解决方案。

第一步: 将你的域名服务器代理至Cloudflare

Cloudflare需要控制您的DNS,因此请按照本指南将名称服务器切换到它们。不用担心,您的DNS设置将保持不变。

Changing your domain nameservers to Cloudflare

这一步很重要,大致可以理解为以下步骤:

将你原来的nameservers更改为Cloudflare提供给你的nameserver

比如我的域名是在阿里云的, 进行如下操作即可(修改后需要过一段时间等Cloudflare发邮箱给你)

在域名解析里添加一条A的记录,IP随便填

当收到邮件后,你的Cloudflare的Overview页会变成这样,就说明更改nameservers成功了

在Cloudflare的DNS页里也添加一条A的记录,IP随便填但是要保证Proxy Status是通的

第二步: 添加工程脚本

Big thanks to Mayne for writing this worker script. You can find the original in this gist.

以下是为你代理域的代码,因此请执行以下操作:

  1. Click on the ”Workers” tab
  2. Click “Launch Editor”
  3. On the left, click ”Add Script”
  4. Name it notion-worker

Once you have followed those steps, copy this script into that new file.

    const MY_DOMAIN = "example.com"
    const START_PAGE = "https://www.notion.so/link/to/your/public/page"

    addEventListener('fetch', event => {
      event.respondWith(fetchAndApply(event.request))
    })

    const corsHeaders = {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Methods": "GET, HEAD, POST,PUT, OPTIONS",
      "Access-Control-Allow-Headers": "Content-Type",
    }

    function handleOptions(request) {
      if (request.headers.get("Origin") !== null &&
        request.headers.get("Access-Control-Request-Method") !== null &&
        request.headers.get("Access-Control-Request-Headers") !== null) {
        // Handle CORS pre-flight request.
        return new Response(null, {
          headers: corsHeaders
        })
      } else {
        // Handle standard OPTIONS request.
        return new Response(null, {
          headers: {
            "Allow": "GET, HEAD, POST, PUT, OPTIONS",
          }
        })
      }
    }

    async function fetchAndApply(request) {
      if (request.method === "OPTIONS") {
        return handleOptions(request)
      }
      let url = new URL(request.url)
      let response
      if (url.pathname.startsWith("/app") && url.pathname.endsWith("js")) {
        response = await fetch(`https://www.notion.so${url.pathname}`)
        let body = await response.text()
        try {
          response = new Response(body.replace(/www.notion.so/g, MY_DOMAIN).replace(/notion.so/g, MY_DOMAIN), response)
          // response = new Response(response.body, response)
          response.headers.set('Content-Type', "application/x-javascript")
          console.log("get rewrite app.js")
        } catch (err) {
          console.log(err)
        }

      } else if ((url.pathname.startsWith("/api"))) {
        response = await fetch(`https://www.notion.so${url.pathname}`, {
          body: request.body, // must match 'Content-Type' header
          headers: {
            'content-type': 'application/json;charset=UTF-8',
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'
          },
          method: "POST", // *GET, POST, PUT, DELETE, etc.
        })
        response = new Response(response.body, response)
        response.headers.set('Access-Control-Allow-Origin', "*")
      } else if (url.pathname === `/`) {
            let pageUrlList = START_PAGE.split("/")
        let redrictUrl = `https://${MY_DOMAIN}/${pageUrlList[pageUrlList.length-1]}`
        return Response.redirect(redrictUrl, 301)
      } else {
        response = await fetch(`https://www.notion.so${url.pathname}${url.search}`, {
          body: request.body, // must match 'Content-Type' header
          headers: request.headers,
          method: request.method, // *GET, POST, PUT, DELETE, etc.
        })
      }

      return response
    }

现在,你已经添加了脚本,您需要更改顶部的两个const:

  1. MY_DOMAIN 表示你需要代理的域名-你自己的域名 ( E.G. example.com)
  2. START_PAGE 表示你代理的目标域名地址-notion的地址(E.G.https://www.notion.so/link/to/your/public/page)

保存你的脚本,然后返回上一层

第三步: 添加一个通配符路径才处理你的所有流量

在这里添加你的域名和通配符,然后在你Worker这一栏选择你刚刚配置的脚本名就可以了

example.com/*

到这里为止就大功告成了! 这时候你访问你自己的域名就可以看到notion的页面啦, 以后用notion写博客也可以使用自己的域名了, 可谓是相当酷炫了!

💎最后,这里有我的示例tomatoro.space