Skip to content

DenkiYagi/takibi

Repository files navigation

Takibi(焚火)

Cloudflare Workersのローカル環境エミュレータ。

Cloudflareの提供するwranglerでは達成し得ない、localhostへのプロキシをローカル環境でエミュレートできます。

使い方

このアプリケーションはHaxeを用いてビルドするため、Haxeのインストールをする必要があります。

また実行には、Node.jsが必要です。

プロジェクトのセットアップ

git clone https://github.com/DenkiYagi/cloudflare-workers-emulator.git
haxelib install build.hxml
npm install

起動方法

npm start $WORKER_SCRIPT_PATH

使用例

~/worker-example/index.js

const PRODUCTION = false

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

/**
 * Respond with hello worker text
 * @param {Request} request
 */
async function handleRequest(request) {
  return await fetch(
    PRODUCTION ? 'https://example.com' : 'http://localhost:8080'
  )
}

~/helloworld-app/index.js

const app = require('express')()
app.get('/', (req, res) => res.end('Hello World!'))
app.listen(8080)

shell

cd ~/helloworld-app
node index &
cd ~/cloudflare-workers-emulator # This repository's directory
npm start ~/worker-example/index.js

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages