From f3a15eb9562c306217a55cc2d045e08c6bcff246 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 15 May 2024 19:40:18 +0500 Subject: [PATCH 1/9] feat(deployment): allow deploy to vercel --- backend/main.py | 5 +++++ backend/vercel.json | 14 ++++++++++++++ frontend/app/api/config.js | 4 ++++ 3 files changed, 23 insertions(+) create mode 100644 backend/vercel.json diff --git a/backend/main.py b/backend/main.py index 3a43338..3c5194b 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,3 +1,5 @@ +import os + import uvicorn from fastapi import FastAPI from modules import proxy @@ -38,6 +40,9 @@ TAGS = [ PREFIX = "/v1" +if os.getenv("API_PREFIX"): + PREFIX = os.getenv("API_PREFIX") + app = FastAPI( openapi_tags=TAGS, title="AniX API", diff --git a/backend/vercel.json b/backend/vercel.json new file mode 100644 index 0000000..70c1e96 --- /dev/null +++ b/backend/vercel.json @@ -0,0 +1,14 @@ +{ + "builds": [ + { + "src": "main.py", + "use": "@vercel/python" + } + ], + "routes": [ + { + "src": "/(.*)", + "dest": "main.py" + } + ] +} diff --git a/frontend/app/api/config.js b/frontend/app/api/config.js index 12a7d2a..7eb8ada 100644 --- a/frontend/app/api/config.js +++ b/frontend/app/api/config.js @@ -1,5 +1,9 @@ export let API_URL = "/api/v1"; +if (process.env.API_URL) { + API_URL = process.env.API_URL; +} + export const endpoints = { index: { last: `${API_URL}/index/last`, From 3c850ccda89f2c82fa6c012e0efb8a315e6b9f34 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 15 May 2024 19:50:01 +0500 Subject: [PATCH 2/9] vercel: trigger build --- .trigger_build | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .trigger_build diff --git a/.trigger_build b/.trigger_build new file mode 100644 index 0000000..e69de29 From c73e84078aa06fab12abd8ee9c4cfa9dc3ce1714 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 15 May 2024 20:10:49 +0500 Subject: [PATCH 3/9] fix(frontend): fix API_URL environment variable being undefined --- backend/main.py | 9 +++++++++ frontend/app/api/config.js | 2 +- frontend/next.config.mjs | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/main.py b/backend/main.py index 3c5194b..b33bf54 100644 --- a/backend/main.py +++ b/backend/main.py @@ -2,6 +2,7 @@ import os import uvicorn from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware from modules import proxy from modules.pages import bookmarks from modules.pages import favorites @@ -52,6 +53,14 @@ app = FastAPI( redoc_url=None, ) +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["GET", "POST"], + allow_headers=["*"], +) + app.include_router(profile.router, prefix=f"{PREFIX}/profile", tags=["Profile"]) app.include_router(auth.router, prefix=f"{PREFIX}/auth", tags=["Profile"]) diff --git a/frontend/app/api/config.js b/frontend/app/api/config.js index 7eb8ada..2491dd2 100644 --- a/frontend/app/api/config.js +++ b/frontend/app/api/config.js @@ -1,4 +1,4 @@ -export let API_URL = "/api/v1"; +let API_URL = "/api/v1"; if (process.env.API_URL) { API_URL = process.env.API_URL; diff --git a/frontend/next.config.mjs b/frontend/next.config.mjs index ac54bb9..d4ce4b0 100644 --- a/frontend/next.config.mjs +++ b/frontend/next.config.mjs @@ -14,6 +14,9 @@ const nextConfig = { }, ], }, + env: { + API_URL: process.env.API_URL, + }, }; export default nextConfig; From 9239dc28c752bc36960b8f7fc04aeb8cdd44739e Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 15 May 2024 20:14:37 +0500 Subject: [PATCH 4/9] fix(vercel/backend): fix missing CORS headers --- backend/vercel.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backend/vercel.json b/backend/vercel.json index 70c1e96..10a307c 100644 --- a/backend/vercel.json +++ b/backend/vercel.json @@ -10,5 +10,23 @@ "src": "/(.*)", "dest": "main.py" } + ], + "headers": [ + { + "key": "Access-Control-Allow-Credentials", + "value": "true" + }, + { + "key": "Access-Control-Allow-Origin", + "value": "*" + }, + { + "key": "Access-Control-Allow-Methods", + "value": "GET,POST" + }, + { + "key": "Access-Control-Allow-Headers", + "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" + } ] } From edcb6a107db17b405bf46f21d78fff5a58714d84 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 15 May 2024 20:18:24 +0500 Subject: [PATCH 5/9] fix(vercel/backend): fix vercel.json headers schema --- backend/vercel.json | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/backend/vercel.json b/backend/vercel.json index 10a307c..efbb1da 100644 --- a/backend/vercel.json +++ b/backend/vercel.json @@ -13,20 +13,25 @@ ], "headers": [ { - "key": "Access-Control-Allow-Credentials", - "value": "true" - }, - { - "key": "Access-Control-Allow-Origin", - "value": "*" - }, - { - "key": "Access-Control-Allow-Methods", - "value": "GET,POST" - }, - { - "key": "Access-Control-Allow-Headers", - "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" + "source": "/(.*)", + "headers": [ + { + "key": "Access-Control-Allow-Credentials", + "value": "true" + }, + { + "key": "Access-Control-Allow-Origin", + "value": "*" + }, + { + "key": "Access-Control-Allow-Methods", + "value": "GET,POST" + }, + { + "key": "Access-Control-Allow-Headers", + "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" + } + ] } ] } From ebc28e7b42da20b20bb8a99e2c22e65090848979 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 15 May 2024 20:23:47 +0500 Subject: [PATCH 6/9] vercel: trigger build --- .trigger_build | 0 backend/vercel.json | 1 + 2 files changed, 1 insertion(+) delete mode 100644 .trigger_build diff --git a/.trigger_build b/.trigger_build deleted file mode 100644 index e69de29..0000000 diff --git a/backend/vercel.json b/backend/vercel.json index efbb1da..cd37f0b 100644 --- a/backend/vercel.json +++ b/backend/vercel.json @@ -1,4 +1,5 @@ { + "$schema": "https://openapi.vercel.sh/vercel.json", "builds": [ { "src": "main.py", From c0d295c78a2556a3c1351ead760e8037aa697946 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 15 May 2024 20:32:09 +0500 Subject: [PATCH 7/9] fix(vercel/backend): fix vercel backend deploy --- backend/vercel.json | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/backend/vercel.json b/backend/vercel.json index cd37f0b..65295de 100644 --- a/backend/vercel.json +++ b/backend/vercel.json @@ -9,30 +9,13 @@ "routes": [ { "src": "/(.*)", - "dest": "main.py" - } - ], - "headers": [ - { - "source": "/(.*)", - "headers": [ - { - "key": "Access-Control-Allow-Credentials", - "value": "true" - }, - { - "key": "Access-Control-Allow-Origin", - "value": "*" - }, - { - "key": "Access-Control-Allow-Methods", - "value": "GET,POST" - }, - { - "key": "Access-Control-Allow-Headers", - "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" - } - ] + "dest": "main.py", + "headers": { + "Access-Control-Allow-Credentials": "true", + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET,POST", + "Access-Control-Allow-Headers": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" + } } ] } From 3b222e0cc521587387e8578392e4101731eef799 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 15 May 2024 21:18:58 +0500 Subject: [PATCH 8/9] docs(readme/deploy): add a vercel deploy instructions --- README.md | 27 +++++++++++++++++++++++++++ backend/README.md | 28 ++++++++++++++++++++++++++++ frontend/README.md | 10 ---------- 3 files changed, 55 insertions(+), 10 deletions(-) delete mode 100644 frontend/README.md diff --git a/README.md b/README.md index 7decdb7..77d9dc2 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ AniX is an unofficial web client for the Android application Anixart. It allows you to access and manage your Anixart account from a web browser on your desktop or laptop computer. +[Changelog](./CHANGELOG.md) + +[Backend Readme](./backend/README.md) + ## Screenshots **User profile page** @@ -89,6 +93,8 @@ To access the docker logs you can use `docker compose -f docker-compose.dev.yml ## Deployment +### first steps + 1. clone this repository via `git clone https://github.com/Radiquum/AniX.git` 2. cd into the repository folder. 3. deploy app with below instructions. @@ -152,6 +158,27 @@ To access the docker logs you can use `docker compose -f docker-compose.dev.yml You can find more details in the Deta Space documentation: [Deta Space Docs](https://docs.deta.space/) +### Vercel + +*note* you don't need to complete the first steps for vercel deploy + +1. [Deploy the backend](./backend/README.md#vercel) and copy the production url, including the prefix +2. create a new project on vercel and set the root directory to frontend +3. set API_URL env variable to copied url +4. click deploy + +#### Available environment variables + +- API_URL - sets the api url to use for frontend to connect to the backend + +#### One-Click Deploy + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/Radiquum/AniX/tree/main/frontend) + +*note*: this will create a new repository. + +*note*: don't forget to set API_URL to backend url. + ## Contributing We welcome contributions to this project! If you have any bug fixes, improvements, or new features, please feel free to create a pull request. diff --git a/backend/README.md b/backend/README.md index e69de29..ae3fc4d 100644 --- a/backend/README.md +++ b/backend/README.md @@ -0,0 +1,28 @@ +# Anix Backend + +This is the backend for AniX, an unofficial WEB client for the Android app Anixart. + +It is using FastAPI and server as a proxy between app API and Web Client. + +## Deployment + +### Environment variables + +- API_PREFIX - sets the api prefix + +### Docker + + [Refer the docker deployment from root README file](../README.md#docker-deployment) + +## Vercel + +1. fork the repository +2. create a new project on vercel and set the root directory to backend +3. (optionally) set API_PREFIX env variable +4. click deploy + +### One-Click Deploy + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/Radiquum/AniX/tree/main/backend) + +*note*: this will create a new repository diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index 8a7fbc0..0000000 --- a/frontend/README.md +++ /dev/null @@ -1,10 +0,0 @@ -This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). - -## Learn More - -To learn more about Next.js, take a look at the following resources: - -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. - -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! From 6fb42c805fef70e58d931d12a000fba219b0fe8f Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 15 May 2024 21:19:02 +0500 Subject: [PATCH 9/9] =?UTF-8?q?bump:=20version=200.10.0=20=E2=86=92=200.11?= =?UTF-8?q?.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cz.yaml | 2 +- CHANGELOG.md | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.cz.yaml b/.cz.yaml index 27d747e..baecdf3 100644 --- a/.cz.yaml +++ b/.cz.yaml @@ -4,5 +4,5 @@ commitizen: name: cz_conventional_commits tag_format: $version update_changelog_on_bump: true - version: 0.10.0 + version: 0.11.0 version_scheme: semver diff --git a/CHANGELOG.md b/CHANGELOG.md index 96ea429..b53f16a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## 0.11.0 (2024-05-15) + +### Feat + +- **deployment**: allow deploy to vercel + +### Fix + +- **vercel/backend**: fix vercel backend deploy +- **vercel/backend**: fix vercel.json headers schema +- **vercel/backend**: fix missing CORS headers +- **frontend**: fix API_URL environment variable being undefined + ## 0.10.0 (2024-05-13) ### Feat