Skip to content

Commit

Permalink
feat: cors-proxy v2
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed May 4, 2024
0 parents commit 37c56b8
Show file tree
Hide file tree
Showing 23 changed files with 3,685 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
*.log*
.nitro
.cache
.output
.env
dist
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_size = 2
indent_style = space
58 changes: 58 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# name: Docker Publish

# on:
# push:
# branches:
# - main

# env:
# REGISTRY: ghcr.io
# IMAGE_NAME: ${{ github.repository }}

# jobs:
# build:
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write
# id-token: write

# steps:
# - name: Checkout repository
# uses: actions/checkout@v4

# - name: Setup Docker buildx
# uses: docker/setup-buildx-action@v3

# - name: Get version
# id: package-version
# uses: martinbeentjes/npm-get-version-action@main

# - name: Log into registry ${{ env.REGISTRY }}
# uses: docker/login-action@v3
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: Extract Docker metadata
# id: meta
# uses: docker/metadata-action@v5
# with:
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# flavor: |
# latest=auto
# tags: |
# type=semver,pattern={{version}},value=v${{ steps.package-version.outputs.current-version }}

# - name: Build and push Docker image
# id: build-and-push
# uses: docker/build-push-action@v5
# with:
# push: true
# platforms: linux/amd64,linux/arm64
# context: .
# labels: ${{ steps.meta.outputs.labels }}
# tags: ${{ steps.meta.outputs.tags }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
68 changes: 68 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# name: Release

# on:
# push:
# branches:
# - main

# jobs:
# release:
# name: Release
# runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v4

# - uses: pnpm/action-setup@v2
# with:
# version: latest

# - name: Get version
# id: package-version
# uses: martinbeentjes/npm-get-version-action@main

# - name: Install packages
# run: pnpm install --frozen-lockfile

# - name: Build for cloudflare
# run: pnpm build:cloudflare && cp ./.output/server/index.mjs ./cloudflare.worker.mjs

# - name: Build for Node
# run: pnpm build:node && cd .output/server && zip -r ../../nodejs.zip .

# - name: Create Release
# id: create_release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: v${{ steps.package-version.outputs.current-version }}
# release_name: cors-proxy v${{ steps.package-version.outputs.current-version }}
# draft: false
# prerelease: false
# body: |
# Instead of downloading a package, you can also run it in docker:
# ```sh
# docker run ghcr.io/spiceitfy/cors-proxy:${{ steps.package-version.outputs.current-version }}
# ```

# - name: Upload cloudflare build
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: ./cloudflare.worker.mjs
# asset_name: cors-proxy-cloudflare.mjs
# asset_content_type: text/javascript

# - name: Upload Node build
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: ./nodejs.zip
# asset_name: cors-proxy-nodejs.zip
# asset_content_type: application/zip
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Linting and Testing

on:
push:
branches:
- main
pull_request:

jobs:
building:
name: Build project
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: latest

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install pnpm packages
run: pnpm install --frozen-lockfile

- name: Build Project
run: pnpm build

docker:
name: Build docker
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Build
uses: docker/build-push-action@v5
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
*.log*
.nitro
.cache
.output
.env
dist
.netlify
4 changes: 4 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
trailingComma: 'all',
singleQuote: true,
};
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:20-alpine as base
WORKDIR /app

# Build layer
FROM base as build

RUN npm i -g pnpm
COPY pnpm-lock.yaml package.json ./
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build

# Production layer
FROM base as production

EXPOSE 3000
ENV NODE_ENV=production
COPY --from=build /app/.output ./.output

CMD ["node", ".output/server/index.mjs"]
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2023 movie-web
Copyright (c) 2024 Spicetify contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# cors-proxy

Simple reverse proxy to bypass CORS, used by [spicetify](https://spicetify.app).

---

### features:
- Deployable on many platforms - thanks to nitro
- header rewrites - read and write protected headers
- bypass CORS - always allows browser to send requests through it

### supported platforms:
- cloudflare workers
- nodejs
34 changes: 34 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.2/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "off"
}
}
},
"formatter": {
"enabled": true,
"formatWithErrors": true,
"indentStyle": "tab",
"indentWidth": 2,
"lineWidth": 150
},
"javascript": {
"formatter": {
"trailingComma": "none",
"arrowParentheses": "asNeeded"
}
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true,
"defaultBranch": "master"
}
}
14 changes: 14 additions & 0 deletions nitro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { join } from "node:path";
import pkg from "./package.json";

//https://nitro.unjs.io/config
export default defineNitroConfig({
noPublicDir: true,
srcDir: "./src",
runtimeConfig: {
version: pkg.version
},
alias: {
"@": join(__dirname, "src")
}
});
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "simple-proxy",
"private": true,
"version": "2.1.4",
"scripts": {
"prepare": "nitropack prepare",
"dev": "nitropack dev",
"build": "nitropack build",
"build:cloudflare": "NITRO_PRESET=cloudflare npm run build",
"build:node": "NITRO_PRESET=node-server npm run build",
"start": "node .output/server/index.mjs",
"preinstall": "npx only-allow pnpm"
},
"dependencies": {
"fetch-cookie": "^3.0.1",
"h3": "^1.10.0",
"nitropack": "^2.8.1"
},
"devDependencies": {
"@rollup/wasm-node": "^4.9.4"
},
"pnpm": {
"overrides": {
"rollup": "npm:@rollup/wasm-node"
}
}
}
Loading

0 comments on commit 37c56b8

Please sign in to comment.