Skip to content

Commit

Permalink
Support caddy auth
Browse files Browse the repository at this point in the history
Signed-off-by: KayleCoder <[email protected]>
  • Loading branch information
KayleCoder committed Oct 12, 2024
1 parent e66112a commit e77be7b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/caddy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ci

on:
push:
branches:
- 'caddy'

jobs:
docker:
if: github.repository == 'crustio/ipfs-w3auth-gateway'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Install dependencies
run: yarn install --immutable

- name: Build bundle
run: yarn build

- name: Dockerize and push
run: |
./dockerize.sh
docker push crustio/ipfs-w3auth-caddy:latest
14 changes: 4 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ server.use(authHandler);
const proxy = httpProxy.createProxyServer({});

server.all('*', (req: Request, res: Response) => {
const target = process.env.IPFS_ENDPOINT || 'http://127.0.0.1:5001';
console.log(`Validation success. Proxying request to ${target}`);

proxy.web(req, res, {target}, error => {
console.error(error);
res.writeHead(500, {'Content-Type': 'application/json'});
res.end(
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(
JSON.stringify({
Error: error.message,
Success: true,
})
);
});
);
});

const port = process.env.PORT || 5050;
Expand Down

0 comments on commit e77be7b

Please sign in to comment.