Skip to content

Commit

Permalink
change for server actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorkham committed Nov 26, 2024
1 parent f078034 commit e96005d
Show file tree
Hide file tree
Showing 11 changed files with 841 additions and 391 deletions.
5 changes: 5 additions & 0 deletions api/health.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { VercelRequest, VercelResponse } from '@vercel/node'

export default function handler(req: VercelRequest, res: VercelResponse) {
res.status(200).json({ message: 'API is healthy!' })
}
25 changes: 25 additions & 0 deletions api/tmdb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { VercelRequest, VercelResponse } from '@vercel/node'

import axios from 'axios'

export default async function handler(req: VercelRequest, res: VercelResponse) {
try {
const { path } = req.query
const tmdbApiKey = process.env.TMDB_API_KEY

if (!path) {
return res.status(400).json({ error: 'Path is required' })
}

const tmdbResponse = await axios.get(
`https://api.themoviedb.org/3${path}`,
{
params: { api_key: tmdbApiKey, ...req.query }
}
)

res.status(200).json(tmdbResponse.data)
} catch (error) {
res.status(500).json({ error: 'An error occurred', details: error.message })
}
}
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@
"description": "An Alpine.js Movie DB application",
"main": "src/main.ts",
"scripts": {
"dev": "concurrently \"npm run dev:front\" \"npm run dev:back\"",
"dev:front": "vite",
"dev:back": "nodemon --watch server server/index.ts",
"build": "npm run build:front && npm run build:back",
"build:front": "vite build",
"build:back": "tsc -p server/tsconfig.json && cp -r server dist/server",
"serve": "concurrently \"npm run serve:front\" \"npm run serve:back\"",
"serve:front": "vite preview",
"serve:back": "node dist/server/index.js",
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
"lint": "eslint .",
"lint:fix": "eslint --fix . && prettier --write .",
"test": "jest",
Expand All @@ -26,6 +20,7 @@
"license": "MIT",
"dependencies": {
"@alpinejs/persist": "^3.14.3",
"@vercel/node": "^3.2.26",
"alpinejs": "^3.14.3",
"autoprefixer": "^10.4.20",
"axios": "^1.7.7",
Expand Down
Loading

0 comments on commit e96005d

Please sign in to comment.