|
| 1 | +<!-- 90da50ec-9cc4-48d8-9ec9-6bba32957580 5b0adcba-53da-4907-a2e8-edfa5fe15ddf --> |
| 2 | +# Fix API: Convert TypeScript to JavaScript Only |
| 3 | + |
| 4 | +## Scope |
| 5 | + |
| 6 | +**HANYA mengubah API backend** - Frontend, tampilan, dan gameplay TIDAK DIUBAH |
| 7 | + |
| 8 | +## Changes |
| 9 | + |
| 10 | +### 1. Create JavaScript API Files |
| 11 | + |
| 12 | +**File: `api/feed.js`** (NEW) |
| 13 | + |
| 14 | +```javascript |
| 15 | +module.exports = async (req, res) => { |
| 16 | + res.setHeader('Access-Control-Allow-Credentials', 'true'); |
| 17 | + res.setHeader('Access-Control-Allow-Origin', '*'); |
| 18 | + res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS,POST,PUT'); |
| 19 | + res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); |
| 20 | + |
| 21 | + if (req.method === 'OPTIONS') { |
| 22 | + return res.status(200).end(); |
| 23 | + } |
| 24 | + |
| 25 | + try { |
| 26 | + const mockPosts = [ |
| 27 | + { |
| 28 | + _id: '1', |
| 29 | + type: 'score', |
| 30 | + author: { |
| 31 | + address: 'ST3RHRNAVPT5ATP2JWJXAB836TV559GPCYCRTVGJR', |
| 32 | + username: 'testuser', |
| 33 | + avatar: null |
| 34 | + }, |
| 35 | + content: 'Just scored 100 points in Snake! 🐍', |
| 36 | + game: { |
| 37 | + slug: 'snake', |
| 38 | + name: 'Snake', |
| 39 | + thumbnail: '/games/snake-thumb.png' |
| 40 | + }, |
| 41 | + score: 100, |
| 42 | + likes: 5, |
| 43 | + tips: [], |
| 44 | + createdAt: new Date().toISOString() |
| 45 | + } |
| 46 | + ]; |
| 47 | + |
| 48 | + return res.status(200).json(mockPosts); |
| 49 | + } catch (error) { |
| 50 | + console.error('Feed error:', error); |
| 51 | + return res.status(500).json({ error: 'Failed to fetch feed' }); |
| 52 | + } |
| 53 | +}; |
| 54 | +``` |
| 55 | + |
| 56 | +**File: `api/health.js`** (NEW) |
| 57 | + |
| 58 | +```javascript |
| 59 | +module.exports = async (req, res) => { |
| 60 | + res.setHeader('Access-Control-Allow-Origin', '*'); |
| 61 | + return res.status(200).json({ |
| 62 | + status: 'ok', |
| 63 | + timestamp: new Date().toISOString(), |
| 64 | + message: 'API is working' |
| 65 | + }); |
| 66 | +}; |
| 67 | +``` |
| 68 | + |
| 69 | +### 2. Update Vercel Config |
| 70 | + |
| 71 | +Update `vercel.json` line 7-15: |
| 72 | + |
| 73 | +```json |
| 74 | +"rewrites": [ |
| 75 | + { |
| 76 | + "source": "/api/feed", |
| 77 | + "destination": "/api/feed.js" |
| 78 | + }, |
| 79 | + { |
| 80 | + "source": "/api/health", |
| 81 | + "destination": "/api/health.js" |
| 82 | + }, |
| 83 | + { |
| 84 | + "source": "/(.*)", |
| 85 | + "destination": "/apps/web/dist/$1" |
| 86 | + } |
| 87 | +] |
| 88 | +``` |
| 89 | + |
| 90 | +### 3. Remove Old TypeScript Files |
| 91 | + |
| 92 | +Delete: |
| 93 | + |
| 94 | +- `api/feed.ts` |
| 95 | +- `api/health.ts` |
| 96 | + |
| 97 | +### 4. Deploy |
| 98 | + |
| 99 | +Run `vercel --prod` to deploy |
| 100 | + |
| 101 | +## What WILL Change |
| 102 | + |
| 103 | +- ✅ API endpoints akan bekerja (tidak crash lagi) |
| 104 | +- ✅ Feed akan load dengan mock data |
| 105 | + |
| 106 | +## What WILL NOT Change |
| 107 | + |
| 108 | +- ❌ Frontend code (React components) |
| 109 | +- ❌ Tampilan UI/UX |
| 110 | +- ❌ Gameplay mechanics |
| 111 | +- ❌ Games (Snake, Tic-tac-toe, etc) |
| 112 | +- ❌ Styling/CSS |
| 113 | +- ❌ User experience |
| 114 | + |
| 115 | +Frontend tetap 100% sama, hanya backend API yang diperbaiki! |
0 commit comments