Deploy OneDrive-Cf-Index

Related repo is here.

Install Node.js environment

Install nodejs and npm, then run these commands.

npm i @cloudflare/binary-install -g
npm i @cloudflare/wrangler -g
npm i @beetcb/ms-graph-cli -g

You may need to set proxy if Internet is limited.

npm config set proxy=http://$IP:$PORT
npm config set https-proxy=http://$IP:$PORT

Get OneDrive API tokens

Open Azure panel and create a new application. Redirect URL should be http://localhost.

Suppose your application ID is $ID.

Then create a client secret, and suppose its value is $VALUE.

Give Microsoft Graph the three permissions below.


At last, run this command and follow its instruction.

npx @beetcb/ms-graph-cli

Suppose your refresh token is $TOKEN.

Remember to create a folder named Public in your OneDrive root directory, which is the folder you share with.

Create a Cloudflare worker

First, clone the repo.

git clone

Then login Cloudflare to give permissions.

wrangler login

You can use this command to make sure you have signed in.

wrangler whoami

Create a worker called $NAME in Cloudflare Workers, then edit wrangler.toml and change name to $NAME, account_id and zone_id properly.

Create a KV namespace.

wrangler kv:namespace create "BUCKET" --preview

Then change id and preview_id in wrangler.toml.

Edit src/config/default.js and change client_id to $ID. Also delete the line refresh_token: REFRESH_TOKEN,.

Open your KV namespace and add a new entry with key refresh_token and value $TOKEN.

Edit /src/auth/onedrive.js and add this line after getAccessToken function.

const refresh_token = await BUCKET.get("refresh_token");

Then change config.refresh_token to refresh_token in that file.

At last, set your password as AUTH_PASSWORD and $VALUE as CLIENT_SECRET.

wrangler secret put AUTH_PASSWORD
wrangler secret put CLIENT_SECRET

Customize pages

Edit src/folderView.js and src/render/htmlWrapper.js.

You can also add custom domains. Simply create a CNAME record, and add a Worker Route with route $DOMAIN/*.


You may want to preview it first.

wrangler preview

If everything is OK, publish it.

wrangler publish