Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from eukarya-inc/add-auto-ogtag
Browse files Browse the repository at this point in the history
Support auto fetch og tag
  • Loading branch information
tomoyane authored Apr 1, 2024
2 parents 6f59f0d + c216a27 commit 9618379
Show file tree
Hide file tree
Showing 18 changed files with 2,673 additions and 1,033 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
express-*
notion-proxy
gcp/
coverage/*
13 changes: 0 additions & 13 deletions Dockerfile

This file was deleted.

25 changes: 25 additions & 0 deletions Dockerfile.amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:18-slim

# See: https://github.com/puppeteer/puppeteer/tree/main/docker
# Install chrome on amd64
RUN apt-get update \
&& apt-get install -y wget gnupg python3 make g++ ca-certificates \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/googlechrome-linux-keyring.gpg \
&& sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/googlechrome-linux-keyring.gpg] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-khmeros fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
&& npm install -g pkg \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd -r pptruser && useradd -rm -g pptruser -G audio,video pptruser

USER pptruser

WORKDIR /notion-proxy
COPY package*.json ./
COPY src ./src

RUN npm ci
RUN pkg src/expressApp.js -o /notion-proxy/app

CMD ["/notion-proxy/app"]
54 changes: 36 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
## Notion proxy
# Notion proxy

Deliver notion pages via your domain.
Reference [fruitionsite](https://github.com/stephenou/fruitionsite) for rewrite html processing.
This proxy does not depend on Cloudflare and launches on express server.

### Node Version
## Node Version

18
`<20.5.1`

### Environment variable
If using version 21.x or above, it will generate a deprecation warning indicating the use of the deprecated punycode module.

| Env | Description | Default |
|-------------------|--------------------------------------------|----------------------------------|
| PAGE_TITLE | Page title on meta tag | "" |
| PAGE_DESC | Page desc on meta tag | "" |
| GOOGLE_FONT | See: `https://developers.google.com/fonts` | "" |
| PROXY_PORT | Proxy port number | 3456 |
| DOMAIN | Proxy domain for rewrite | localhost:3456 |
| IS_TLS | Proxy tls(http/https) for rewrite | false |
| NOTION_PAGE_ID | Notion public page id | f1db0cfbe246475784c67f279289abea |
| CUSTOM_SCRIPT | Custom script | "" |
| CONTENT_CACHE_SEC | Cache time for loaded content (sec) | 300 |
## Environment variable

### Getting started
| ProxyConfig | Description | Default |
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
| PROXY_PORT | Proxy port number | "3456" |
| DOMAIN | Proxy domain for rewrite | "localhost:3456" |
| IS_TLS | Proxy tls(http/https) for rewrite | "false" |
| NOTION_PAGE_ID | Notion public page id | "f1db0cfbe246475784c67f279289abea" |
| CUSTOM_SCRIPT | Custom script | "" |
| CONTENT_CACHE_SEC | Cache time for loaded content (sec) | "300" |
| GOOGLE_FONT | See: `https://developers.google.com/fonts` | "" |
| AUTO_SET_OGP | The server automatically extracts Open Graph Protocol (OGP) data from your NotionId upon startup. <br/>When this feature is enabled, the values of `OG_TAG_TITLE` and `OG_TAG_IMAGE_URL` are utilized for automatic configuration.<br/>If you prefer to wait until the OGP tags are fetched automatically, you can use the `/readyz` command.<br/><br/>Requirements<br/>- Headless chrome<br/>- CPU is always allocated<br/>- At least 512MB of memory for better | "false" |
| OG_TAG_TITLE | Title for og tag | "" |
| OG_TAG_DESC | Description for og tag | "" |
| OG_TAG_IMAGE_URL | Image url for og tag | "" |
| OG_TAG_TYPE | Type for og tag | "website" |
| TWITTER_CARD | Twitter card for og tag | "summary_large_image" |

### Note for AUTO_SET_OGP variable

**OgTag setting priority**

Environment variables with OG_xxx in prefix are set with the highest priority.
So, if AUTO_SET_OGP is enabled but the OG_xxx environment variable is set, OG_xxx will have priority.

**Headless chrome Requirements**

At startup, we are extracting og tags from the NotionId page using Chrome Headless.
So, CPU allocation is necessary. Please be cautious when using request allocation in services like Cloud Functions or Cloud Run or Other.

## Getting started

Start proxy for debug on local.

Expand All @@ -32,7 +50,7 @@ $ npm test
$ npm start_proxy
> [email protected] start
> node src/index.js
NotionProxy listening at localhost:3456, NotionId: f1db0cfbe246475784c67f279289abea
Proxy listening at localhost:3456, NotionId: f1db0cfbe246475784c67f279289abea
```

Start proxy binary.
Expand All @@ -41,5 +59,5 @@ Start proxy binary.
$ npm install -g pkg
$ npm run build
$ ./notion-proxy
NotionProxy listening at localhost:3456, NotionId: f1db0cfbe246475784c67f279289abea
Proxy listening at localhost:3456, NotionId: f1db0cfbe246475784c67f279289abea
```
Loading

0 comments on commit 9618379

Please sign in to comment.