Skip to content

Commit

Permalink
feat: integrate the frontend inside astro
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher2K committed Nov 28, 2024
1 parent 4da1d03 commit 544b116
Show file tree
Hide file tree
Showing 60 changed files with 5,551 additions and 3,781 deletions.
2 changes: 1 addition & 1 deletion swapify_api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ API_URL=http://localhost:4000
APPLE_MUSIC_KID=
APPLE_MUSIC_PRIVATE_KEY=""
APPLE_MUSIC_TEAM_ID=
APP_URL=http://localhost:5173
APP_URL=http://localhost:4321
DATABASE_URL=postgres://admin:swapifypassword@localhost:5432/swapify
JWT_SECRET=
PLATFORM_HOST=localhost
Expand Down
2 changes: 1 addition & 1 deletion swapify_api/.env.test.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
API_URL=http://localhost:4000
APPLE_MUSIC_PRIVATE_KEY=
APP_URL=http://localhost:5173
APP_URL=http://localhost:4321
DATABASE_URL=postgres://admin:swapifypassword@localhost:54321/swapify_test
JWT_SECRET=
PLATFORM_HOST=localhost
16 changes: 8 additions & 8 deletions swapify_api/lib/swapify_api/emails.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule SwapifyApi.Emails do

require EEx

alias SwapifyApi.Utils

@no_reply_sender {"Swapify - Notifications", "[email protected]"}

EEx.function_from_file(
Expand All @@ -16,7 +18,7 @@ defmodule SwapifyApi.Emails do
)

def welcome(email, name, options \\ []) do
app_url = Keyword.get(options, :app_url)
app_url = Utils.get_app_url()
username = Keyword.get(options, :username)
{:ok, template} = welcome_template(username, app_url) |> Mjml.to_html()

Expand Down Expand Up @@ -44,7 +46,7 @@ defmodule SwapifyApi.Emails do
)

def transfer_ready(email, name, options \\ []) do
app_url = Keyword.get(options, :app_url)
app_url = Utils.get_app_url()
username = Keyword.get(options, :username)
source_name = Keyword.get(options, :source_name)
destination_name = Keyword.get(options, :destination_name)
Expand Down Expand Up @@ -84,7 +86,7 @@ defmodule SwapifyApi.Emails do
)

def transfer_error(email, name, options \\ []) do
app_url = Keyword.get(options, :app_url)
app_url = Utils.get_app_url()
username = Keyword.get(options, :username)
source_name = Keyword.get(options, :source_name)
destination_name = Keyword.get(options, :destination_name)
Expand Down Expand Up @@ -115,7 +117,7 @@ defmodule SwapifyApi.Emails do
)

def transfer_done(email, name, options \\ []) do
app_url = Keyword.get(options, :app_url)
app_url = Utils.get_app_url()
username = Keyword.get(options, :username)
source_name = Keyword.get(options, :source_name)
destination_name = Keyword.get(options, :destination_name)
Expand Down Expand Up @@ -144,10 +146,8 @@ defmodule SwapifyApi.Emails do
)

def password_reset_request(email, name, opts \\ []) do
app_url = Utils.get_app_url()
code = Keyword.get(opts, :code)

app_url = Application.fetch_env!(:swapify_api, :app_url)

reset_url = app_url <> "/password-reset/#{code}"

{:ok, template} =
Expand All @@ -174,7 +174,7 @@ defmodule SwapifyApi.Emails do
)

def welcome_beta(email, name) do
app_url = Application.fetch_env!(:swapify_api, :app_url)
app_url = Utils.get_app_url()

{:ok, template} =
welcome_beta_template(name, app_url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ defmodule SwapifyApi.MusicProviders.Jobs.FindPlaylistTracksJob do
with {:ok, %{email: email, username: username}} <- Accounts.get_by_id(user_id),
{:ok, transfer} <- Tasks.get_transfer_infos(transfer_id) do
SwapifyApi.Emails.transfer_ready(email, username,
app_url: Application.fetch_env!(:swapify_api, :app_url),
username: username,
source_name: PlatformConnection.get_name(transfer.source),
destination_name: PlatformConnection.get_name(transfer.destination),
Expand Down Expand Up @@ -133,7 +132,6 @@ defmodule SwapifyApi.MusicProviders.Jobs.FindPlaylistTracksJob do
{:ok, %{username: username}} <- Accounts.get_by_id(user_id),
{:ok, transfer} <- Tasks.get_transfer_infos(transfer_id) do
SwapifyApi.Emails.transfer_error(transfer.email, username,
app_url: Application.fetch_env!(:swapify_api, :app_url),
username: username,
source_name: PlatformConnection.get_name(transfer.source),
destination_name: PlatformConnection.get_name(transfer.destination)
Expand Down
6 changes: 5 additions & 1 deletion swapify_api/lib/swapify_api/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ defmodule SwapifyApi.Utils do
|> Enum.join(".")
end

def get_app_url("/" <> _path = path), do: Application.fetch_env!(:swapify_api, :app_url) <> path
def get_app_url("/" <> _path = path),
do: Application.fetch_env!(:swapify_api, :app_url) <> "/app" <> path

def get_app_url(),
do: Application.fetch_env!(:swapify_api, :app_url) <> "/app"

@doc """
Handle Oban insertion errors
Expand Down
14 changes: 7 additions & 7 deletions swapify_api/lib/swapify_api_web/controllers/auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ defmodule SwapifyApiWeb.AuthController do
alias SwapifyApi.Utils

# Shared rate limit
rate_limit(
"auth",
[:sign_up, :new_password_reset_request, :confirm_password_reset_request],
:timer.minutes(30),
10
)
# rate_limit(
# "auth",
# [:sign_up, :new_password_reset_request, :confirm_password_reset_request],
# :timer.minutes(30),
# 100
# )

def sign_up(%Plug.Conn{} = conn, _) do
data = conn.body_params
Expand Down Expand Up @@ -42,7 +42,7 @@ defmodule SwapifyApiWeb.AuthController do
conn
|> delete_session(:access_token)
|> delete_session(:refresh_token)
|> redirect(external: Utils.get_app_url("/"))
|> redirect(external: Utils.get_app_url())
end

def new_password_reset_request(conn, _) do
Expand Down
6 changes: 3 additions & 3 deletions swapify_web/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VITE_API_URL=http://localhost:4000
VITE_APP_URL=http://localhost:3000
VITE_HIGHLIGHT_APP_ID=
PUBLIC_API_URL=http://localhost:4000
PUBLIC_APP_URL=http://localhost:3000
PUBLIC_HIGHLIGHT_APP_ID=
35 changes: 19 additions & 16 deletions swapify_web/.gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@

# build output
dist/
dist
.solid
.output
.vercel
.netlify
.vinxi

# Environment
.env
.env*.local
# generated types
.astro/

# dependencies
/node_modules
node_modules/

# IDEs and editors
/.idea
.project
.classpath
*.launch
.settings/
# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Temp
gitignore

# System Files
# environment variables
.env
.env.production

# macOS-specific files
.DS_Store
Thumbs.db

# jetbrains setting folder
.idea/

## Panda
styled-system
styled-system-studio
styled-system-studio
1 change: 1 addition & 0 deletions swapify_web/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"plugins": ["prettier-plugin-astro"],
"semi": true,
"trailingComma": "all",
"tabWidth": 2,
Expand Down
32 changes: 32 additions & 0 deletions swapify_web/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @ts-no-check
import { defineConfig } from "astro/config";
import svgr from "vite-plugin-svgr";
import tsconfigPaths from "vite-tsconfig-paths";

import react from "@astrojs/react";

import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({
output: "server",
integrations: [react()],

vite: {
build: {
sourcemap: true,
},
plugins: [
tsconfigPaths(),
svgr({
svgrOptions: {
exportType: "default",
},
}),
],
},

adapter: node({
mode: "standalone",
}),
});
15 changes: 0 additions & 15 deletions swapify_web/index.html

This file was deleted.

28 changes: 14 additions & 14 deletions swapify_web/nixpacks.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
providers = ["node"]

[variables]
CADDY_VERSION = '2.8.2'
# CADDY_VERSION = '2.8.2'
NIXPACKS_NODE_VERSION = '20'

[phases.setup]
nixPkgs = ['...', 'jq']
nixpkgsArchive = '505ad1607f7e54426cfb2d804e48fa2c247f32ba'

[phases.caddy]
dependsOn = ['setup']
cmds = [
'curl -fsSLo caddy.tar.gz "https://github.com/caddyserver/caddy/releases/download/v${CADDY_VERSION}/caddy_${CADDY_VERSION}_linux_amd64.tar.gz"',
'tar -zxvf caddy.tar.gz caddy',
'chmod +x caddy'
]
# [phases.caddy]
# dependsOn = ['setup']
# cmds = [
# 'curl -fsSLo caddy.tar.gz "https://github.com/caddyserver/caddy/releases/download/v${CADDY_VERSION}/caddy_${CADDY_VERSION}_linux_amd64.tar.gz"',
# 'tar -zxvf caddy.tar.gz caddy',
# 'chmod +x caddy'
# ]

[phases.codegen]
dependsOn = ['install']
Expand All @@ -38,11 +38,11 @@ cmds = [
"find dist -name '*.js.map' -type f -delete"
]

[phases.fmt]
dependsOn = ['caddy']
cmds = ['caddy fmt --overwrite Caddyfile']
# [phases.fmt]
# dependsOn = ['caddy']
# cmds = ['caddy fmt --overwrite Caddyfile']

[start]
runImage = 'ubuntu:20.04'
onlyIncludeFiles = ['caddy', 'Caddyfile', 'dist']
cmd = './caddy run --config Caddyfile --adapter caddyfile 2>&1'
# runImage = 'ubuntu:20.04'
# onlyIncludeFiles = ['caddy', 'Caddyfile', 'dist']
cmd = "node dist/server/entry.mjs"
58 changes: 31 additions & 27 deletions swapify_web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,58 @@
"type": "module",
"version": "0.0.1",
"scripts": {
"prepare": "panda codegen",
"panda:watch": "panda -w",
"dev": "concurrently \"pnpm panda:watch\" \"pnpm vite\"",
"build": "panda && tsc -b && vite build",
"preview": "vite preview",
"astro": "astro",
"build": "panda && astro check && astro build",
"dev": "concurrently \"pnpm panda:watch\" \"astro dev\"",
"format": "prettier --write .",
"typecheck": "tsc --noEmit",
"lint": "prettier --check ."
"lint": "prettier --check .",
"panda:watch": "panda -w",
"prepare": "panda codegen",
"preview": "astro preview",
"typecheck": "noEmit"
},
"dependencies": {
"@ark-ui/react": "~3.6.2",
"@astrojs/check": "^0.9.4",
"@astrojs/node": "^8.3.4",
"@astrojs/react": "^3.6.3",
"@highlight-run/react": "~7.0.2",
"@hookform/resolvers": "~3.9.0",
"@pandacss/dev": "~0.45.0",
"@park-ui/panda-preset": "~0.42.0",
"@tanstack/react-query": "~5.51.23",
"@tanstack/react-router": "~1.47.1",
"@tanstack/react-router": "~1.83.1",
"@tanstack/router-devtools": "~1.83.1",
"@tanstack/router-plugin": "~1.83.1",
"@ts-react/form": "~1.8.3",
"@ts-rest/core": "~3.51.0",
"@ts-rest/react-query": "~3.51.0",
"@types/musickit-js": "~1.0.9",
"@types/node": "~22.2.0",
"@types/phoenix": "~1.6.5",
"@types/react": "^18.3.12",
"@types/react-dom": "~18.3.0",
"@vitejs/plugin-react": "~4.3.1",
"astro": "^4.16.16",
"burnt": "~0.12.2",
"concurrently": "~8.2.2",
"date-fns": "~4.1.0",
"globals": "~15.9.0",
"highlight.run": "~9.5.2",
"javascript-time-ago": "~2.5.11",
"ky": "~1.3.0",
"lucide-react": "~0.427.0",
"phoenix": "~1.7.14",
"prettier": "~3.3.3",
"prettier-plugin-astro": "~0.14.1",
"prettier-plugin-organize-imports": "~4.1.0",
"react": "~18.3.1",
"react-dom": "~18.3.1",
"react-hook-form": "~7.52.2",
"zod": "~3.23.8"
},
"devDependencies": {
"@pandacss/dev": "~0.45.0",
"@park-ui/panda-preset": "~0.42.0",
"@tanstack/router-devtools": "~1.47.1",
"@tanstack/router-plugin": "~1.47.0",
"@types/musickit-js": "~1.0.9",
"@types/node": "~22.2.0",
"@types/phoenix": "~1.6.5",
"@types/react": "~18.3.3",
"@types/react-dom": "~18.3.0",
"@vitejs/plugin-react": "~4.3.1",
"concurrently": "~8.2.2",
"globals": "~15.9.0",
"prettier": "~3.3.3",
"prettier-plugin-organize-imports": "~4.1.0",
"typescript": "~5.5.3",
"typescript": "~5.7.2",
"vite": "~5.4.0",
"vite-plugin-svgr": "~4.2.0",
"vite-tsconfig-paths": "~4.3.2"
"vite-tsconfig-paths": "~4.3.2",
"zod": "~3.23.8"
}
}
Loading

0 comments on commit 544b116

Please sign in to comment.