mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-04 13:19:57 +00:00
Initial commit
This commit is contained in:
28
routes/api/git/stacks/[id]/deploy/+server.ts
Normal file
28
routes/api/git/stacks/[id]/deploy/+server.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { getGitStack } from '$lib/server/db';
|
||||
import { deployGitStack } from '$lib/server/git';
|
||||
import { authorize } from '$lib/server/authorize';
|
||||
|
||||
export const POST: RequestHandler = async ({ params, cookies }) => {
|
||||
const auth = await authorize(cookies);
|
||||
|
||||
try {
|
||||
const id = parseInt(params.id);
|
||||
const gitStack = await getGitStack(id);
|
||||
if (!gitStack) {
|
||||
return json({ error: 'Git stack not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
// Permission check with environment context
|
||||
if (auth.authEnabled && !await auth.can('stacks', 'start', gitStack.environmentId || undefined)) {
|
||||
return json({ error: 'Permission denied' }, { status: 403 });
|
||||
}
|
||||
|
||||
const result = await deployGitStack(id);
|
||||
return json(result);
|
||||
} catch (error) {
|
||||
console.error('Failed to deploy git stack:', error);
|
||||
return json({ error: 'Failed to deploy git stack' }, { status: 500 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user