# GFCL Client Portal – cPanel Deployment Guide

এই প্রজেক্টটি **cPanel** এ চালানোর জন্য দুইটি উপায় আছে।

---

## Option 1: Node.js App (Recommended) ✅

আধুনিক cPanel এ **Setup Node.js App** ফিচার থাকে। এটি সবচেয়ে ভালো কাজ করে।

### Step-by-step:

1. **cPanel → Software → Setup Node.js App** এ যান।

2. **Create Application** ক্লিক করুন:
   - Node.js version: **18.x** বা **20.x** (সর্বনিম্ন 18.17)
   - Application mode: **Production**
   - Application root: `noc` (অথবা আপনার পছন্দমতো ফোল্ডার, যেমন `client-portal`)
   - Application URL: `noc.gfclbd.com` (অথবা subdomain তৈরি করে নিন)
   - Application startup file: `server.js` (পরে বদলাব)

3. **Create** করুন।

4. এখন Terminal বা File Manager দিয়ে Application root ফোল্ডারে যান।

5. পুরো প্রজেক্ট আপলোড করুন (zip extract করে)।

6. Terminal এ লিখুন:

```bash
cd ~/noc   # আপনার application root
npm install --production
npm run build
```

7. Build শেষ হলে `.next/standalone` ফোল্ডার তৈরি হবে।

8. **Startup file** পরিবর্তন করুন:
   - cPanel Node.js App এ গিয়ে **Edit** করুন
   - Application startup file: `.next/standalone/server.js`
   - অথবা root এ একটা `server.js` বানান:

```js
// server.js (root এ রাখুন)
const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')
const path = require('path')

const dev = false
const hostname = '0.0.0.0'
const port = process.env.PORT || 3000

const app = next({ 
  dev, 
  dir: path.join(__dirname),
  conf: { distDir: '.next' }
})
const handle = app.getRequestHandler()

app.prepare().then(() => {
  createServer(async (req, res) => {
    try {
      const parsedUrl = parse(req.url, true)
      await handle(req, res, parsedUrl)
    } catch (err) {
      console.error('Error occurred handling', req.url, err)
      res.statusCode = 500
      res.end('internal server error')
    }
  }).listen(port, hostname, () => {
    console.log(`> Ready on http://${hostname}:${port}`)
  })
})
```

9. **Restart** App করুন।

10. Domain/Subdomain (`noc.gfclbd.com`) পয়েন্ট করে দিন।

---

## Option 2: Static Export (যদি Node.js না থাকে)

যদি আপনার cPanel এ Node.js App না থাকে, তাহলে pure HTML বানিয়ে `public_html` এ আপলোড করতে পারেন।

### পরিবর্তন করুন:

`next.config.ts` ফাইলে:

```ts
output: "export",
```

তারপর:

```bash
npm install
npm run build
```

`out` ফোল্ডার তৈরি হবে। এই `out` ফোল্ডারের সব কিছু `public_html` বা subdomain ফোল্ডারে আপলোড করুন।

**Limitation:** কিছু client-side feature (dynamic routing) সীমিত থাকতে পারে।

---

## Domain Setup (noc.gfclbd.com)

1. cPanel → **Domains** / **Subdomains**
2. Subdomain তৈরি করুন: `noc`
3. Document Root: Node.js application root অথবা `public_html/noc`
4. SSL (Let's Encrypt) চালু করুন।

---

## Environment Variables (Optional)

cPanel Node.js App এ Environment Variables এ যোগ করতে পারেন:

```
NODE_ENV=production
PORT=3000
```

---

## Troubleshooting

| সমস্যা | সমাধান |
|--------|--------|
| 503 / App not starting | Startup file সঠিক কিনা চেক করুন + Restart |
| Module not found | `npm install --production` আবার চালান |
| Port issue | cPanel automatically PORT দেয়, manually set করবেন না |
| CSS not loading | `npm run build` সঠিকভাবে হয়েছে কিনা দেখুন |

---

## Recommended File Structure on cPanel

```
/home/username/
└── noc/                          ← Application root
    ├── .next/
    ├── node_modules/
    ├── public/
    ├── src/
    ├── package.json
    ├── next.config.ts
    ├── server.js                 ← (optional custom)
    └── ...
```

---

**সাপোর্ট দরকার হলে** আমাকে জানাবেন।  
GFCL Client Portal ready for production on cPanel.
