-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcd7822
commit 7f7c93d
Showing
5 changed files
with
47 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,48 @@ | ||
import { createSanityProject, createVercelProject, triggerGithubWorkflow } from '@/lib/services'; | ||
import { headers } from 'next/headers'; | ||
|
||
import { isValidEmail } from '@/lib/email'; | ||
|
||
export async function POST(request: Request) { | ||
if (headers().get('authorization') !== `Bearer ${process.env.ROLL_OUT_API_TOKEN}`) { | ||
return new Response('Invalid roll-out token', { status: 401 }); | ||
} | ||
|
||
const { email } = await request.json(); | ||
const username = email | ||
.split('@')[0] | ||
.toLowerCase() | ||
.replace(/[^a-z0-9]/g, '') // prevent forbidden symbols | ||
.slice(0, 90); // prevent project name from being too long | ||
|
||
const sanityProjectId = await createSanityProject(username); | ||
const sanityDatasetName = process.env.NEXT_PUBLIC_SANITY_DATASET || 'production'; | ||
|
||
if (sanityProjectId) { | ||
const projectData = await createVercelProject({ | ||
projectNamePrifix: username, | ||
sanityProjectId: sanityProjectId, | ||
sanityDatasetName, | ||
}); | ||
|
||
if (projectData) { | ||
await triggerGithubWorkflow({ | ||
sanityProjectId, | ||
|
||
if (email && isValidEmail(email)) { | ||
const username = email | ||
.split('@')[0] | ||
.toLowerCase() | ||
.replace(/[^a-z0-9]/g, '') // prevent forbidden symbols | ||
.slice(0, 90); // prevent project name from being too long | ||
|
||
const sanityProjectId = await createSanityProject(username); | ||
const sanityDatasetName = process.env.NEXT_PUBLIC_SANITY_DATASET || 'production'; | ||
|
||
if (sanityProjectId) { | ||
const projectData = await createVercelProject({ | ||
projectNamePrifix: username, | ||
sanityProjectId: sanityProjectId, | ||
sanityDatasetName, | ||
vercelProjectId: projectData.projectId, | ||
vercelProjectName: projectData.projectName, | ||
vercelDeploymentUrl: projectData.deploymentUrl, | ||
email, | ||
}); | ||
|
||
return Response.json({ ok: true, status: 200, statusText: 'All steps were successful 🎉' }); | ||
if (projectData) { | ||
await triggerGithubWorkflow({ | ||
sanityProjectId, | ||
sanityDatasetName, | ||
vercelProjectId: projectData.projectId, | ||
vercelProjectName: projectData.projectName, | ||
vercelDeploymentUrl: projectData.deploymentUrl, | ||
email, | ||
}); | ||
|
||
return Response.json({ ok: true, status: 200, statusText: 'All steps were successful 🎉' }); | ||
} | ||
} | ||
|
||
return Response.json({ status: '503', statusText: 'One of the steps was not successful😿' }); | ||
} | ||
|
||
return Response.json({ status: '503', statusText: 'One of the steps was not successful😿' }); | ||
return Response.json({ status: '400', statusText: 'Email is not valid' }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function isValidEmail(email: string) { | ||
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; | ||
|
||
return emailRegex.test(email); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters