使用cloudflare-workers作为CDN

1.添加记录

在DNS记录中添加一条IPv6记录指向100::。(WHY?)

type name content
AAAA cdn 100::

2.创建worker

创建一个worker代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
addEventListener("fetch", event => {
event.respondWith(handleRequest(event))
})

const BUCKET_NAME = "akame-moe"
const BUCKET_URL = `https://storage.googleapis.com/${BUCKET_NAME}`

async function serveAsset(event) {
const url = new URL(event.request.url)
const cache = caches.default
let response = await cache.match(event.request)

if (!response) {
response = await fetch(`${BUCKET_URL}${url.pathname}`)
const headers = { "cache-control": "public, max-age=14400" }
response = new Response(response.body, { ...response, headers })
event.waitUntil(cache.put(event.request, response.clone()))
}
return response
}

async function handleRequest(event) {
if (event.request.method === "GET") {
let response = await serveAsset(event)
if (response.status > 399) {
response = new Response(response.statusText, { status: response.status })
}
return response
} else {
return new Response("Method not allowed", { status: 405 })
}
}

Read More

implement an authenticating link using nginx-module-njs

sometimes, we need an authenticated link to provent our resources form abusing.
now we will accomplish that by using nginx-module-njs. here we go.

install nginx and nginx-module-njs module

1
2
3
4
5
wget http://nginx.org/keys/nginx_signing.key -O nginx_signing.key
sudo apt-key add nginx_signing.key
echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install nginx nginx-module-njs

Read More

通过travis-ci自动部署代码到服务器

Auto-Deploying via Travis CI

Because Travis CI can automatically execute scripts after successfully (or unsuccessfully!) executing tests, it is an obvious choice for a deployment tool. In order to deploy to a Git repository on a remote server, the process generally is as follows:

  • Set up SSH keys
  • Add the server’s copy of the repository as a Git remote
  • Push to the remote
  • SSH into the server and execute any installation/compilation/miscellaneous commands

Read More

rust编译器在windows下的安装

1.编译器的安装

打开在rust官网下载的rustup-init.exe,由于rust编译器依赖于c/c++编译器,需要gcc/g++,所以如果你电脑没有这个环境控制台就会提示你安装vistual studio(最低版本2013)。
不过我嫌这个工具太大所以使用msys2来替代它。msys2是Windows平台下的包含gcc/g++的编译工具。打开msys2(https://www.msys2.org/)官网,下载后按照文档一步步安装即可。

Read More