mirror of
https://github.com/ryanwtf7/hianime-api.git
synced 2026-04-17 13:31:44 +00:00
fix: vercel module resolution, ci workflow triggers, and readme cleanup
This commit is contained in:
2
.github/workflows/package.yml
vendored
2
.github/workflows/package.yml
vendored
@@ -31,7 +31,6 @@ jobs:
|
|||||||
quality-checks:
|
quality-checks:
|
||||||
name: Code Quality & Security
|
name: Code Quality & Security
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'push' || github.event_name == 'pull_request'
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -74,7 +73,6 @@ jobs:
|
|||||||
name: Build & Test
|
name: Build & Test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: quality-checks
|
needs: quality-checks
|
||||||
if: github.event_name == 'push' || github.event_name == 'pull_request'
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|||||||
20
README.md
20
README.md
@@ -215,14 +215,7 @@ docker-compose up -d
|
|||||||
1. Fork or clone the repository to your GitHub account
|
1. Fork or clone the repository to your GitHub account
|
||||||
2. Sign up at [Vercel](https://vercel.com)
|
2. Sign up at [Vercel](https://vercel.com)
|
||||||
3. Create a new project and import your repository
|
3. Create a new project and import your repository
|
||||||
4. Configure environment variables in Vercel Dashboard:
|
4. Click "Deploy"
|
||||||
- `UPSTASH_REDIS_REST_URL` (Required - Get from [Upstash](https://upstash.com))
|
|
||||||
- `UPSTASH_REDIS_REST_TOKEN` (Required)
|
|
||||||
- `ORIGIN=*` (or your frontend domain)
|
|
||||||
- `RATE_LIMIT_ENABLED=true`
|
|
||||||
- `RATE_LIMIT_WINDOW_MS=60000`
|
|
||||||
- `RATE_LIMIT_LIMIT=100`
|
|
||||||
5. Click "Deploy"
|
|
||||||
|
|
||||||
**Why Vercel?**
|
**Why Vercel?**
|
||||||
-  Serverless architecture with automatic scaling
|
-  Serverless architecture with automatic scaling
|
||||||
@@ -230,18 +223,7 @@ docker-compose up -d
|
|||||||
-  Free tier with generous limits
|
-  Free tier with generous limits
|
||||||
-  Automatic HTTPS and custom domains
|
-  Automatic HTTPS and custom domains
|
||||||
-  Git-based deployments (auto-deploy on push)
|
-  Git-based deployments (auto-deploy on push)
|
||||||
-  Built-in Redis support via Upstash
|
|
||||||
|
|
||||||
**Environment Variables:**
|
|
||||||
|
|
||||||
| Key | Value | Required |
|
|
||||||
|-----|-------|----------|
|
|
||||||
| `UPSTASH_REDIS_REST_URL` | Your Upstash Redis URL | Yes |
|
|
||||||
| `UPSTASH_REDIS_REST_TOKEN` | Your Upstash Redis Token | Yes |
|
|
||||||
| `ORIGIN` | `*` or your domain | No |
|
|
||||||
| `RATE_LIMIT_ENABLED` | `true` | No |
|
|
||||||
| `RATE_LIMIT_WINDOW_MS` | `60000` | No |
|
|
||||||
| `RATE_LIMIT_LIMIT` | `100` | No |
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
98
api/index.ts
98
api/index.ts
@@ -1,46 +1,62 @@
|
|||||||
import app from '../src/app';
|
import { Hono } from 'hono';
|
||||||
|
import { handle } from 'hono/vercel';
|
||||||
|
import { cors } from 'hono/cors';
|
||||||
|
import { logger } from 'hono/logger';
|
||||||
|
import hiAnimeRoutes from '../src/routes/routes';
|
||||||
|
import config from '../src/config/config';
|
||||||
|
import { AppError } from '../src/utils/errors';
|
||||||
|
import { fail } from '../src/utils/response';
|
||||||
|
|
||||||
type VercelResponse = {
|
const app = new Hono();
|
||||||
status: (code: number) => VercelResponse;
|
|
||||||
setHeader: (name: string, value: string) => VercelResponse;
|
|
||||||
send: (body: string | object | Buffer) => VercelResponse;
|
|
||||||
json: (body: object) => VercelResponse;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default async function handler(
|
// CORS Configuration
|
||||||
req: {
|
const origins = config.origin.includes(',')
|
||||||
headers: Record<string, string | string[] | undefined>;
|
? config.origin.split(',').map(o => o.trim())
|
||||||
method: string;
|
: config.origin === '*'
|
||||||
url: string;
|
? '*'
|
||||||
body: unknown;
|
: [config.origin];
|
||||||
},
|
|
||||||
res: VercelResponse
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
const protocol = req.headers['x-forwarded-proto'] || 'https';
|
|
||||||
const host = req.headers['x-forwarded-host'] || req.headers.host;
|
|
||||||
const url = `${protocol}://${host}${req.url}`;
|
|
||||||
const webRequest = new Request(url, {
|
|
||||||
method: req.method,
|
|
||||||
headers: new Headers(req.headers as Record<string, string>),
|
|
||||||
body: req.method !== 'GET' && req.method !== 'HEAD' ? JSON.stringify(req.body) : undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
const webResponse = await app.fetch(webRequest);
|
app.use(
|
||||||
res.status(webResponse.status);
|
'*',
|
||||||
webResponse.headers.forEach((value: string, key: string) => {
|
cors({
|
||||||
res.setHeader(key, value);
|
origin: origins,
|
||||||
});
|
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||||
|
allowHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
|
||||||
|
exposeHeaders: ['Content-Length', 'X-Request-Id'],
|
||||||
|
maxAge: 600,
|
||||||
|
credentials: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
const body = await webResponse.text();
|
// Logging
|
||||||
res.send(body);
|
if (!config.isProduction || config.enableLogging) {
|
||||||
} catch (error: unknown) {
|
app.use('/api/v2/*', logger());
|
||||||
const err = error as Error;
|
|
||||||
console.error('Vercel handler error:', err);
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
error: 'Internal Server Error',
|
|
||||||
message: err.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Health Check
|
||||||
|
app.get('/ping', (c) => {
|
||||||
|
return c.json({
|
||||||
|
status: 'ok',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
environment: 'vercel',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Routes
|
||||||
|
app.route('/api/v2', hiAnimeRoutes);
|
||||||
|
|
||||||
|
// Error Handling
|
||||||
|
app.onError((err, c) => {
|
||||||
|
if (err instanceof AppError) {
|
||||||
|
return fail(c, err.message, err.statusCode, err.details);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error('Vercel Unexpected Error:', err.message);
|
||||||
|
return fail(c, 'Internal server error', 500);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.notFound((c) => {
|
||||||
|
return fail(c, 'Route not found', 404);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default handle(app);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hianime-api",
|
"name": "hianime-api",
|
||||||
"version": "2.0.0",
|
"version": "2.0.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user