Skip to content

Commit 0a0b661

Browse files
committed
Test deployment and API updates
1 parent 91bfe53 commit 0a0b661

File tree

13 files changed

+108
-421
lines changed

13 files changed

+108
-421
lines changed

.github/workflows/deploy.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,20 @@ jobs:
2525
MONGODB_URI: ${{ secrets.MONGODB_URI }}
2626
JWT_SECRET: ${{ secrets.JWT_SECRET }}
2727
BREVO_API_KEY: ${{ secrets.BREVO_API_KEY }}
28+
BREVO_SENDER_EMAIL: ${{ secrets.BREVO_SENDER_EMAIL }}
29+
BREVO_SENDER_NAME: ${{ secrets.BREVO_SENDER_NAME }}
30+
GMAIL_CLIENT_ID: ${{ secrets.GMAIL_CLIENT_ID }}
31+
GMAIL_CLIENT_SECRET: ${{ secrets.GMAIL_CLIENT_SECRET }}
32+
GMAIL_REFRESH_TOKEN: ${{ secrets.GMAIL_REFRESH_TOKEN }}
33+
GMAIL_USER: ${{ secrets.GMAIL_USER }}
34+
RECIPIENT: ${{ secrets.RECIPIENT }}
2835
run: npm run build
2936

37+
- name: Create restart marker (Passenger)
38+
run: |
39+
mkdir -p tmp
40+
date +%s > tmp/restart.txt
41+
3042
- name: Deploy via FTP to cPanel
3143
uses: SamKirkland/[email protected]
3244
with:
@@ -44,7 +56,7 @@ jobs:
4456
**/out/**
4557
**/.env*
4658
**/README.md
47-
**/deploy.yml
59+
**/.github/workflows/**
4860
**/deploy.sh
4961
5062
- name: Notify deployment completion

deploy.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ echo "🚀 Starting automated Node.js deployment..."
99
APP_DIR="/home/csulb/public_html"
1010
NODE_APP_NAME="acm-website"
1111

12+
# Optional Next.js base path for subfolder deploys (e.g., /acm). Leave empty for root.
13+
export NEXT_BASE_PATH="${NEXT_BASE_PATH:-}"
14+
export NEXT_ASSET_PREFIX="${NEXT_ASSET_PREFIX:-}"
15+
16+
# Ensure host/port are compatible with cPanel Node.js app
17+
export HOST="0.0.0.0"
18+
export PORT="${PORT:-3000}"
19+
1220
# Function to check if Node.js app exists
1321
check_node_app() {
1422
echo "📋 Checking if Node.js app exists..."
@@ -20,7 +28,7 @@ check_node_app() {
2028
install_dependencies() {
2129
echo "📦 Installing dependencies..."
2230
cd $APP_DIR
23-
npm install --production
31+
npm ci --omit=dev || npm install --production
2432
if [ $? -eq 0 ]; then
2533
echo "✅ Dependencies installed successfully"
2634
else
@@ -48,7 +56,11 @@ restart_app() {
4856
# This would use cPanel API to restart the app
4957
echo "⚠️ Manual step required: Please restart your Node.js app in cPanel"
5058
echo " 1. Go to cPanel → Node.js Apps"
51-
echo " 2. Find your app and click 'Restart'"
59+
echo " 2. Click 'Install NPM Modules' (installs prod deps)"
60+
echo " 3. Click 'Run JS Script' → Build command: npm run build"
61+
echo " 4. Ensure the 'Application startup file' is server.js"
62+
echo " 5. Add Environment Variables if needed: NEXT_BASE_PATH, NEXT_ASSET_PREFIX, JWT_SECRET, MONGODB_URI, BREVO_API_KEY"
63+
echo " 6. Click 'Restart'"
5264
}
5365

5466
# Main deployment process

lib/admin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import clientPromise from './mongodb';
2-
import bcrypt from 'bcrypt';
2+
import bcrypt from 'bcryptjs';
33

44
export async function getAdminByEmail(email) {
55
const client = await clientPromise;

lib/brevo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const SENDER = {
66
email: process.env.BREVO_SENDER_EMAIL,
77
name: process.env.BREVO_SENDER_NAME,
88
};
9-
const BASE_URL = 'https://acmcsulb.com';
9+
const BASE_URL = 'https://csulb.acm.org';
1010

1111
/**
1212
* Send an email via Brevo SMTP API, including List-Unsubscribe headers.

middleware.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
import { NextResponse } from 'next/server';
2-
import jwt from 'jsonwebtoken';
3-
4-
const SECRET_KEY = process.env.JWT_SECRET;
52

3+
// Note: Middleware runs on the Edge runtime, avoid Node-only libs like 'jsonwebtoken'.
4+
// We only check for the presence of a token and defer verification to API routes/pages.
65
export function middleware(req) {
7-
const authHeader = req.headers.get('Authorization');
8-
const token = req.cookies.get('token') || authHeader?.split(' ')[1];
6+
const authHeader = req.headers.get('authorization');
7+
const bearer = authHeader?.split(' ')[1];
8+
const cookieToken = req.cookies.get('token')?.value;
9+
const token = bearer || cookieToken;
910

1011
if (!token) {
1112
return NextResponse.redirect(new URL('/login', req.url));
1213
}
1314

14-
try {
15-
jwt.verify(token, SECRET_KEY);
16-
return NextResponse.next(); // Allow access if token is valid
17-
} catch (error) {
18-
console.error('Token verification failed:', error.message);
19-
return NextResponse.redirect(new URL('/login', req.url));
20-
}
15+
return NextResponse.next();
2116
}
2217

2318
// Protect specific routes

next.config.mjs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
/** @type {import('next').NextConfig} */
2+
const isProd = process.env.NODE_ENV === 'production';
3+
4+
// Allow overriding basePath/assetPrefix via env so we can deploy to domain root or a subfolder (e.g., /acm)
5+
const envBasePath = process.env.NEXT_BASE_PATH; // e.g. "/acm" or undefined for root
6+
const basePath = envBasePath && envBasePath !== '/' ? envBasePath : undefined;
7+
const assetPrefix = process.env.NEXT_ASSET_PREFIX || (basePath ? `${basePath}/` : undefined);
8+
29
const nextConfig = {
310
// Dynamic deployment - no static export
411
// output: "export", // static export
@@ -9,12 +16,38 @@ const nextConfig = {
916
domains: ["localhost", "csulb.acm.org"], // Add your domain here
1017
},
1118

12-
// Configure for subfolder deployment
13-
basePath: "/acm",
14-
assetPrefix: "/acm/",
19+
// Only set when provided
20+
...(basePath ? { basePath } : {}),
21+
...(assetPrefix ? { assetPrefix } : {}),
22+
23+
// Memory optimization for cPanel/low-memory environments
24+
experimental: {
25+
// Reduce memory usage during build
26+
memoryBasedWorkers: false,
27+
},
1528

16-
// If deploying to root:
17-
// basePath: '/',
18-
// assetPrefix: '/',
29+
// Webpack optimization for memory (client-side only)
30+
webpack: (config, { isServer }) => {
31+
if (!isServer) {
32+
config.optimization.splitChunks = {
33+
chunks: 'all',
34+
cacheGroups: {
35+
default: {
36+
minChunks: 1,
37+
priority: -20,
38+
reuseExistingChunk: true,
39+
},
40+
vendor: {
41+
test: /[\\/]node_modules[\\/]/,
42+
name: 'vendors',
43+
priority: -10,
44+
chunks: 'all',
45+
},
46+
},
47+
};
48+
}
49+
return config;
50+
},
1951
};
52+
2053
export default nextConfig;

0 commit comments

Comments
 (0)