rename: hunhin → huahin (domain correction to huahin.propkk.com)

This commit is contained in:
Your Name committed 2026-08-01 20:41:55 -04:00
1 parent 1dbc378bdb
commit df5a22c512
7 files changed
+480

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
PORT=3056
DATABASE_URL="postgresql://postgres:password@localhost:5132/huahindb?schema=public"
NODE_ENV=production
APP_URL="https://api.huahin.propkk.com"
BACKEND_PUBLIC_URL="https://api.huahin.propkk.com"
CORS_ORIGIN="https://admin.huahin.propkk.com,https://spa.huahin.propkk.com,https://huahin.propkk.com"
JWT_SECRET="replace-with-huahin-production-secret"
OMISE_SECRET_KEY=""
@@ -0,0 +1,31 @@
server {
listen 80;
server_name admin.huahin.propkk.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name admin.huahin.propkk.com;
ssl_certificate /etc/letsencrypt/live/admin.huahin.propkk.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/admin.huahin.propkk.com/privkey.pem;
root /usr/share/nginx/html/huahin/admin;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires max;
log_not_found off;
}
}
@@ -0,0 +1,32 @@
server {
listen 80;
server_name api.huahin.propkk.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name api.huahin.propkk.com;
client_max_body_size 20m;
ssl_certificate /etc/letsencrypt/live/api.huahin.propkk.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.huahin.propkk.com/privkey.pem;
location / {
proxy_pass http://192.168.1.167:3056;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
@@ -0,0 +1,38 @@
server {
listen 80;
server_name huahin.propkk.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name huahin.propkk.com;
ssl_certificate /etc/letsencrypt/live/huahin.propkk.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/huahin.propkk.com/privkey.pem;
location / {
proxy_pass http://192.168.1.167:3007;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
location /_next/static/ {
proxy_pass http://192.168.1.167:3007;
proxy_http_version 1.1;
proxy_set_header Host $host;
add_header Cache-Control "public, max-age=31536000, immutable";
}
}
@@ -0,0 +1,31 @@
server {
listen 80;
server_name spa.huahin.propkk.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name spa.huahin.propkk.com;
ssl_certificate /etc/letsencrypt/live/spa.huahin.propkk.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/spa.huahin.propkk.com/privkey.pem;
root /usr/share/nginx/html/huahin/spa;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires max;
log_not_found off;
}
}
+156
View File
@@ -0,0 +1,156 @@
#!/bin/bash
# ==============================================================================
# HuaHin Project - Integrated Deployment Script (post-receive hook)
# ==============================================================================
# 1. TARGET PATHS (Nginx & PM2)
TARGET_SPA="/home/ti/projects/MyNginxMain/nginx/html/huahin/spa"
TARGET_ADMIN="/home/ti/projects/MyNginxMain/nginx/html/huahin/admin"
TARGET_BACKEND="/home/ti/projects/huahin-api"
TARGET_WEBSITE="/home/ti/projects/huahin-website"
# 2. REPOSITORY CONFIG
REPO="/home/ti/git/huahin-website.git"
BRANCH="master"
TEMP_DIR="/tmp/huahin_build_$(date +%s)"
# 3. BINARY PATHS & PM2
BUN="/home/ti/.bun/bin/bun"
PM2="/home/ti/.nvm/versions/node/v22.17.1/bin/pm2"
PM2_NAME_BACKEND="huahin-backend"
PM2_NAME_WEBSITE="huahin-website"
export PATH="$PATH:/home/ti/.bun/bin:/home/ti/.nvm/versions/node/v22.17.1/bin"
# 4. BUILD ENVIRONMENT
export VITE_API_URL="https://api.huahin.propkk.com/api"
export NEXT_PUBLIC_API_URL="https://api.huahin.propkk.com/api"
# Customer-specific values. Fill these in on the server if enabled.
export VITE_LIFF_ID="${VITE_LIFF_ID:-}"
export VITE_OMISE_PUBLIC_KEY="${VITE_OMISE_PUBLIC_KEY:-}"
# Service ports. Nginx proxies to these ports.
BACKEND_PORT=3056
SSR_PORT=3007
# ------------------------------------------------------------------------------
# START DEPLOYMENT
# ------------------------------------------------------------------------------
set -e
echo "------- Starting Full Deployment: HuaHin Platform -------"
# A. Prepare Temp Source from Checkout
echo "Cloning branch $BRANCH to temporary directory: $TEMP_DIR"
mkdir -p $TEMP_DIR
git --work-tree=$TEMP_DIR --git-dir=$REPO checkout -f $BRANCH
cd $TEMP_DIR
echo "Installing monorepo dependencies..."
$BUN install
# B. Build & Deploy SPA
echo ">>> Building SPA..."
cd apps/spa
$BUN run build
echo "Deploying SPA to $TARGET_SPA..."
mkdir -p $TARGET_SPA
rm -rf $TARGET_SPA/*
cp -rv dist/* $TARGET_SPA/
cd ../..
# C. Build & Deploy ADMIN PANEL
echo ">>> Building Admin Panel..."
cd apps/admin
$BUN run build
echo "Deploying Admin Panel to $TARGET_ADMIN..."
mkdir -p $TARGET_ADMIN
rm -rf $TARGET_ADMIN/*
cp -rv dist/* $TARGET_ADMIN/
cd ../..
# D. Deploy & Manage BACKEND (API)
echo ">>> Updating Backend at $TARGET_BACKEND..."
mkdir -p $TARGET_BACKEND
mkdir -p $TARGET_BACKEND/apps
mkdir -p $TARGET_BACKEND/packages
rsync -av --delete \
--exclude='.env' \
--exclude='public/' \
--exclude='node_modules/' \
apps/backend/ $TARGET_BACKEND/apps/backend/
rsync -av packages/ $TARGET_BACKEND/packages/
cp package.json bun.lock ecosystem.config.js $TARGET_BACKEND/
sed -i 's/homaroma/huahin/g' $TARGET_BACKEND/ecosystem.config.js
sed -i 's/PORT: 3002/PORT: 3007/g' $TARGET_BACKEND/ecosystem.config.js
cd $TARGET_BACKEND
echo "Installing backend dependencies..."
$BUN install
mkdir -p $TARGET_BACKEND/apps/backend/public
cd $TARGET_BACKEND/apps/backend
echo ">>> Generating Prisma Client..."
$BUN x prisma generate
if [ ! -f "$TARGET_BACKEND/.env" ]; then
echo "Error: .env file is missing at $TARGET_BACKEND/.env. Deployment aborted."
exit 1
fi
cp "$TARGET_BACKEND/.env" "$TARGET_BACKEND/apps/backend/.env"
echo ">>> Running Prisma Migrate Deploy..."
$BUN x prisma migrate deploy
# E. PM2 Management - BACKEND
echo ">>> Managing PM2 Process: $PM2_NAME_BACKEND..."
$PM2 startOrReload $TARGET_BACKEND/ecosystem.config.js --only $PM2_NAME_BACKEND --env production --update-env
echo "PM2 process '$PM2_NAME_BACKEND' is running. Waiting 10s for it to fully start..."
sleep 10
# F. Build & Deploy WEBSITE (Next.js SSR)
echo ">>> Building Next.js SSR App inside monorepo temp dir..."
cd $TEMP_DIR/apps/website
$BUN run build
# G. Prepare Next.js SSR
echo ">>> Preparing Next.js SSR App..."
rsync -av --delete \
$TEMP_DIR/apps/website/.next/standalone/ $TARGET_WEBSITE/
rsync -av \
$TEMP_DIR/apps/website/public/ $TARGET_WEBSITE/apps/website/public/
rsync -av \
$TEMP_DIR/apps/website/.next/static/ $TARGET_WEBSITE/apps/website/.next/static/
cp $TEMP_DIR/ecosystem.config.js $TARGET_WEBSITE/
sed -i 's/homaroma/huahin/g' $TARGET_WEBSITE/ecosystem.config.js
sed -i 's/PORT: 3002/PORT: 3007/g' $TARGET_WEBSITE/ecosystem.config.js
# H. Fix Permissions
echo ">>> Fixing Permissions..."
chown -R ti:ti $TARGET_BACKEND $TARGET_WEBSITE
# I. PM2 Management - SSR Next.js
cd $TARGET_WEBSITE
echo ">>> Creating symlink for .next..."
ln -sf apps/website/.next .next
echo ">>> Managing PM2 Process: $PM2_NAME_WEBSITE..."
$PM2 startOrReload $TARGET_WEBSITE/ecosystem.config.js --only $PM2_NAME_WEBSITE --env production --update-env
echo "PM2 process '$PM2_NAME_WEBSITE' is running."
# J. Cleanup
echo "Cleaning up build artifacts..."
rm -rf $TEMP_DIR
echo "------- ALL DEPLOYMENTS COMPLETED SUCCESSFULLY -------"
echo ""
echo "Service Summary:"
echo " Website (SSR) -> https://huahin.propkk.com (PM2: $PM2_NAME_WEBSITE, Port: $SSR_PORT)"
echo " SPA -> https://spa.huahin.propkk.com"
echo " Admin Panel -> https://admin.huahin.propkk.com"
echo " API Backend -> https://api.huahin.propkk.com (PM2: $PM2_NAME_BACKEND, Port: $BACKEND_PORT)"