({ request, params }: ActionFunctionArgs)
| 6 | import { InitializeDeploymentService } from "~/v3/services/initializeDeployment.server"; |
| 7 | |
| 8 | export async function action({ request, params }: ActionFunctionArgs) { |
| 9 | // Ensure this is a POST request |
| 10 | if (request.method.toUpperCase() !== "POST") { |
| 11 | return { status: 405, body: "Method Not Allowed" }; |
| 12 | } |
| 13 | |
| 14 | // Next authenticate the request |
| 15 | const authenticationResult = await authenticateApiRequest(request); |
| 16 | |
| 17 | if (!authenticationResult) { |
| 18 | logger.info("Invalid or missing api key", { url: request.url }); |
| 19 | return json({ error: "Invalid or Missing API key" }, { status: 401 }); |
| 20 | } |
| 21 | |
| 22 | const rawBody = await request.json(); |
| 23 | const body = InitializeDeploymentRequestBody.safeParse(rawBody); |
| 24 | |
| 25 | if (!body.success) { |
| 26 | return json({ error: "Invalid body", issues: body.error.issues }, { status: 400 }); |
| 27 | } |
| 28 | |
| 29 | const authenticatedEnv = authenticationResult.environment; |
| 30 | |
| 31 | const service = new InitializeDeploymentService(); |
| 32 | |
| 33 | const { deployment, imageTag } = await service.call(authenticatedEnv, body.data); |
| 34 | |
| 35 | const responseBody: InitializeDeploymentResponseBody = { |
| 36 | id: deployment.friendlyId, |
| 37 | contentHash: deployment.contentHash, |
| 38 | shortCode: deployment.shortCode, |
| 39 | version: deployment.version, |
| 40 | externalBuildData: deployment.externalBuildData as InitializeDeploymentResponseBody["externalBuildData"], |
| 41 | imageTag, |
| 42 | registryHost: env.DEPLOY_REGISTRY_HOST |
| 43 | } |
| 44 | |
| 45 | return json( |
| 46 | responseBody, |
| 47 | { status: 200 } |
| 48 | ); |
| 49 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…