Deploy Frontend
The Next.js frontend is hosted on AWS Amplify and auto-deploys when changes are pushed to the staging or main branches.
Automatic Deployments
| Branch | Environment | Trigger |
|---|---|---|
staging |
Staging | Merge PR to staging |
main |
Production | Merge PR to main |
How It Works
- A pull request is merged into
staging(ormain). - Amplify detects the push and starts a build.
- Amplify runs
npm run buildfor the Next.js application. - On success, the new version is deployed and the URL is updated.
Build logs are available in the Amplify Console.
Checking Build Status
Via Amplify Console
- Open the Amplify Console in the PhD Advantage AWS account (
735234196709). - Select the branch (
stagingormain). - View the build status and logs.
Via AWS CLI
aws amplify list-jobs \
--app-id d1vpp3bmermmyp \
--branch-name staging \
--profile dissertation-editor
Manual Redeploy
If you need to redeploy without a code change (e.g., after updating Amplify environment variables):
- Open the Amplify Console.
- Select the branch.
- Click Redeploy this version.
Alternatively, via CLI:
aws amplify start-job \
--app-id d1vpp3bmermmyp \
--branch-name staging \
--job-type RELEASE \
--profile dissertation-editor
Updating Environment Variables
Frontend environment variables are configured in the Amplify Console, not in the codebase.
Step 1: Update the Variable
- Open the Amplify Console for the app.
- Go to Hosting > Environment variables.
- Add a new variable or update an existing one.
Current variables:
| Variable | Description |
|---|---|
NEXT_PUBLIC_TOKEN_ENDPOINT |
Full URL for the LiveKit token API endpoint |
NEXT_PUBLIC_API_URL |
Base URL for all backend API calls |
Step 2: Trigger a Redeploy
Environment variable changes do not take effect until the next build. Trigger a manual redeploy after updating variables.
Build Configuration
Amplify uses the amplify.yml build specification (or auto-detected Next.js settings). The build process:
- Installs dependencies:
npm install - Builds the application:
npm run build - Deploys the output (SSR-enabled Next.js)
Troubleshooting
| Problem | Solution |
|---|---|
| Build fails with dependency errors | Check package-lock.json is committed. Amplify runs npm ci which requires the lockfile. |
| Build succeeds but site shows old content | Clear browser cache or open in incognito. Check if the build deployed to the correct branch. |
| Environment variable not working | Ensure the variable name starts with NEXT_PUBLIC_ if it needs to be available in the browser. Redeploy after updating. |
| Build timeout | Amplify has a default 30-minute build timeout. If the build is slow, check for large dependencies or optimize the build. |
| 404 on dynamic routes | Ensure the Amplify rewrite rules are configured to serve the Next.js application for all routes. |
Deployment Order
When changes span both backend and frontend:
- Deploy backend first -- Lambda functions and API Gateway must be updated before the frontend expects new endpoints or response formats.
- Merge frontend PR to staging -- Amplify auto-deploys and uses the already-updated backend.
- Test on staging.
- Merge to main for production.
This order ensures backward compatibility during the deployment window.