Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/workflows/nodejs.yml

This file was deleted.

12 changes: 2 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
/target
/dist
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log
worker/
node_modules/
.cargo-ok
.vercel/
.vercel
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ See [DEVELOPMENT.md](./docs/development.md).

## Supported by CodeSandbox

This project is [officially supported](https://codesandbox.io/docs/importing#using-githubboxcom) and sponsored by CodeSandbox.
This project is [officially supported](https://codesandbox.io/docs/importing#using-githubboxcom) and sponsored by CodeSandbox.
80 changes: 67 additions & 13 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,84 @@
## githubbox

The site uses Cloudflare Workers to redirect visitors to CodeSandbox.
The site is a static [Vercel](https://vercel.com/) deployment which redirects
visitors to CodeSandbox. There is no application code: the redirects are
declared in `vercel.json` and handled by Vercel's CDN, so they run in every
region without invoking a function.

See [redirect.md](./redirect.md) for the redirect setup.

## Editing the worker
## Layout

To edit the worker, open `src/index.js`.
The `src` directory contains the Cloudflare worker.
- `vercel.json` holds the redirect rules
- `public/robots.txt` is served as a static file. Vercel serves this project's
static files out of `public/`, so a `robots.txt` at the repo root is not
reachable — it has to live here

## Building and publishing a new version
## Editing

You need to install [wrangler](https://github.com/cloudflare/wrangler) globally.
To edit the redirect logic, open `vercel.json`. The rules are matched in order,
first match wins:

### Publishing to development
| Source | Goes to |
| ------------------------------- | ------------------------------------------ |
| `/` and `/index.html` | this repo on GitHub |
| `/:owner/:repo/blob/:ref/:file+` | the sandbox for `:ref`, with `:file` opened |
| `/:owner/:repo/tree/:rest+` | the sandbox for that branch, tag or commit |
| `/:owner/:repo` | the sandbox for the repo's default branch |

Anything else falls through to a 404, which is what we want for paths like
`/issues` or `/zeit/ms/stargazers`.

The `+` modifier requires at least one segment, so `/zeit/ms/tree` alone is a
404 rather than a redirect to an empty ref.

## Running locally

```
vercel dev
```

Then check http://localhost:3000/zeit/ms

## Testing

There is nothing to unit test, so verify against a deployment instead. Point
`BASE` at a preview URL and check the `location` headers:

```
BASE=https://githubbox.com
for path in \
/ \
/zeit/ms \
/zeit/ms/ \
/zeit/ms/tree/main \
/zeit/ms/tree/2.1.1 \
/zeit/ms/blob/main/package.json \
/zeit/ms/blob/main/lib/index.js \
/robots.txt \
/issues \
/zeit/ms/stargazers
do
echo "$path -> $(curl -sI "$BASE$path" | head -n1 | tr -d '\r')"
done
```

The last two should be 404s. `/robots.txt` should be a 200.

## Deploying

### Preview

```
yarn pub
vercel
```

Then check https://githubbox.dferber.workers.dev/
Then check the preview URL that gets printed.

### Publishing to production
### Production

```
yarn pub:prod
vercel --prod
```

Then check https://githubbox.com
Expand All @@ -34,9 +88,9 @@ Then check https://githubbox.com
All these forms of URLs are supported.

- main [githubbox.com/zeit/ms](https://githubbox.com/zeit/ms)
- branch [githubbox.com/zeit/ms/tree/master](https://githubbox.com/zeit/ms/tree/master)
- branch [githubbox.com/zeit/ms/tree/main](https://githubbox.com/zeit/ms/tree/main)
- tree [githubbox.com/zeit/ms/tree/2.1.1](https://githubbox.com/zeit/ms/tree/2.1.1)
- commit [githubbox.com/zeit/ms/tree/7920885eb232fbe7a5efdab956d3e7c507c92ddf](https://githubbox.com/zeit/ms/tree/7920885eb232fbe7a5efdab956d3e7c507c92ddf)
- branch with file [githubbox.com/zeit/ms/blob/master/package.json](https://githubbox.com/zeit/ms/blob/master/package.json)
- branch with file [githubbox.com/zeit/ms/blob/main/package.json](https://githubbox.com/zeit/ms/blob/main/package.json)
- tree with file [githubbox.com/zeit/ms/blob/2.0.0/index.js](https://githubbox.com/zeit/ms/blob/2.0.0/index.js)
- commit with file [githubbox.com/zeit/ms/blob/adf1eb282d29fe3c405d205a3854177b86a97c1f/index.js](https://githubbox.com/zeit/ms/blob/adf1eb282d29fe3c405d205a3854177b86a97c1f/index.js)
31 changes: 0 additions & 31 deletions package.json

This file was deleted.

3 changes: 3 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
40 changes: 0 additions & 40 deletions src/index.js

This file was deleted.

93 changes: 0 additions & 93 deletions src/index.spec.js

This file was deleted.

25 changes: 0 additions & 25 deletions src/location.js

This file was deleted.

32 changes: 32 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"outputDirectory": "public",
"trailingSlash": false,
"redirects": [
{
"source": "/",
"destination": "https://github.com/dferber90/githubbox",
"statusCode": 302
},
{
"source": "/index.html",
"destination": "https://github.com/dferber90/githubbox",
"statusCode": 302
},
{
"source": "/:owner/:repo/blob/:ref/:file+",
"destination": "https://codesandbox.io/s/github/:owner/:repo/tree/:ref?file=/:file+",
"statusCode": 302
},
{
"source": "/:owner/:repo/tree/:rest+",
"destination": "https://codesandbox.io/s/github/:owner/:repo/tree/:rest+",
"statusCode": 302
},
{
"source": "/:owner/:repo",
"destination": "https://codesandbox.io/s/github/:owner/:repo",
"statusCode": 302
}
]
}
Loading