1. Deployment එක සඳහා සූදානම් වීම
App එක deploy කිරීමට පෙර, කරුණු කිහිපයක් තහවුරු කර ගත යුතුය.
➡️ Git සහ GitHub/GitLab
Vercel වැනි නූතන hosting platforms, Git repositories සමඟ ඉතා හොඳින් ක්රියා කරයි. ඔබේ project එක GitHub, GitLab, හෝ Bitbucket වැනි සේවාවක repository එකකට push කර තිබිය යුතුය.
- ඔබේ project folder එකේ terminal එක open කර
git initcommand එක run කරන්න. .gitignorefile එකක් සාදා,node_modules,.env.local, සහnotes.dbයන files/folders ඊට ඇතුළත් කරන්න. (Database file එක commit නොකළ යුතුය).- GitHub හි අලුත් repository එකක් සාදා, ඔබේ project එක ඊට push කරන්න.
➡️ Environment Variables
අපි .env.local file එකේ ගබඩා කළ JWT_SECRET එක Vercel හිදී වෙනම සකස් කළ යුතුය. Vercel dashboard එකේ "Environment Variables" section එකේදී මෙය ඇතුළත් කළ හැක.
2. Vercel මත Deploy කිරීම
Vercel යනු Next.js නිර්මාතෘවරුන්ගේ platform එක වන අතර, Next.js apps deploy කිරීමට ඇති පහසුම සහ හොඳම ක්රමයකි.
- Vercel.com වෙත ගොස්, ඔබේ GitHub/GitLab ගිණුම සමඟ ලියාපදිංචි වන්න.
- Vercel dashboard එකේ, "Add New... -> Project" තෝරන්න.
- ඔබේ Git provider (GitHub) එකෙන් අදාළ project repository එක Import කරන්න.
- Vercel ස්වයංක්රීයවම එය Next.js project එකක් බව හඳුනාගනු ඇත.
- "Environment Variables" section එක expand කර,
JWT_SECRETඑක සහ එහි අගය ඇතුළත් කරන්න. - "Deploy" button එක click කරන්න.
මිනිත්තු කිහිපයක් ඇතුළත, Vercel ඔබේ project එක build කර, deploy කර, ඔබට public URL එකක් ලබා දෙනු ඇත!
3. Production එකේදී SQLite Database එක Handle කිරීම
notes.db file එක) නැති වී යයි. කුඩා, personal projects සඳහා මෙය ගැටළුවක් නොවිය හැකි නමුත්, සැබෑ production app එකක් සඳහා මෙය සුදුසු නැත.
මෙම ගැටළුවට විසඳුම් කිහිපයක් ඇත:
- Committed Database (Not Recommended):
notes.dbfile එක Git repository එකට commit කිරීම. මෙය ඉතා කුඩා, වෙනස් නොවන දත්ත සඳහා පමණක් සුදුසුයි. Highly not recommended for dynamic data. - Persistent Storage: Vercel වැනි platform එකකට සම්බන්ධ කළ හැකි persistent storage සේවාවක් (උදා: AWS S3, Vercel Blob Storage) භාවිතා කර database file එක එහි ගබඩා කිරීම.
- Hosted Database (Best Solution): Turso, Supabase, Neon, හෝ PlanetScale වැනි SQLite-compatible hosted database සේවාවක් භාවිතා කිරීම. මෙය production-grade applications සඳහා ඇති හොඳම විසඳුමයි.
➡️ Production එකේදී Migrations Run කිරීම
අලුතින් deploy කළ විට, database එක හිස්ව පවතී. අපේ tables (users, notes) නිර්මාණය කිරීමට migration script එක run කළ යුතුය. Vercel build process එකේදී command එකක් run කිරීමට, package.json file එකේ scripts section එක වෙනස් කළ යුතුය.
// In package.json
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"postinstall": "node ./init-db.js" // Add this line
}
postinstall script එක, Vercel විසින් project dependencies install කළ වහාම run වේ. එමගින් init-db.js script එක run වී, notes.db file එක සහ අවශ්ය tables නිර්මාණය වනු ඇත.
✅ පාඨමාලාව අවසානයි!
සුභ පැතුම්! ඔබ දැන් Next.js සහ SQLite භාවිතා කරමින්, user authentication සහ CRUD functionality සහිත සම්පූර්ණ full-stack web application එකක් මුල සිට ගොඩනගා, එය deploy කරන ආකාරයද ඉගෙන ගෙන ඇත.
මෙම පාඨමාලාවෙන් ඔබ ලබාගත් දැනුම, තවත් සංකීර්ණ සහ විශාල projects නිර්මාණය කිරීමට ශක්තිමත් අඩිතාලමක් වනු ඇත. ඉදිරියටත් නව දේවල් ඉගෙන ගනිමින්, ඔබේ skills වර්ධනය කරගන්න!