Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add advanced setting for enabling plain HTTP domains #403

Merged
merged 15 commits into from
Feb 10, 2025
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.untracked.*
node-compile-cache/


*.cpuprofile


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ function EditDialog(props: {
}
)) {
const domainFormSchema = yup.object({
domain: urlSchema
.url("Invalid URL")
.transform((value) => 'https://' + value)
domain: yup.string()
// .url("Invalid URL")
TheCactusBlue marked this conversation as resolved.
Show resolved Hide resolved
.notOneOf(
props.domains
.filter((_, i) => (props.type === 'update' && i !== props.editIndex) || props.type === 'create')
Expand All @@ -44,6 +43,7 @@ function EditDialog(props: {
.matches(/^\//, "Handler path must start with /")
.defined(),
addWww: yup.boolean(),
allowInsecureHttp: yup.boolean(),
});

const canAddWww = (domain: string | undefined) => {
Expand Down Expand Up @@ -71,6 +71,7 @@ function EditDialog(props: {
addWww: props.type === 'create',
domain: props.type === 'update' ? props.defaultDomain.replace(/^https:\/\//, "") : undefined,
handlerPath: props.type === 'update' ? props.defaultHandlerPath : "/handler",
allowInsecureHttp: false,
}}
onOpenChange={props.onOpenChange}
trigger={props.trigger}
Expand All @@ -84,11 +85,11 @@ function EditDialog(props: {
domains: [
...props.domains,
{
domain: values.domain,
domain: (values.allowInsecureHttp ? 'http' : 'https') + `://` + values.domain,
handlerPath: values.handlerPath,
},
...(canAddWww(values.domain.slice(8)) && values.addWww ? [{
domain: 'https://www.' + values.domain.slice(8),
...(canAddWww(values.domain) && values.addWww ? [{
domain: `${values.allowInsecureHttp ? 'http' : 'https'}://www.` + values.domain,
handlerPath: values.handlerPath,
}] : []),
],
Expand Down Expand Up @@ -119,7 +120,7 @@ function EditDialog(props: {
label="Domain"
name="domain"
control={form.control}
prefixItem='https://'
prefixItem={form.getValues('allowInsecureHttp') ? 'http://' : 'https://'}
placeholder='example.com'
/>

Expand All @@ -145,6 +146,16 @@ function EditDialog(props: {
<Typography variant="secondary" type="footnote">
only modify this if you changed the default handler path in your app
</Typography>
<div className="my-4">
<SwitchField
label="Allow insecure HTTP domains"
name="allowInsecureHttp"
control={form.control}
/>
</div>
<Typography variant="secondary" type="footnote">
Warning: HTTP domains are insecure and should only be used for development / internal networks.
</Typography>
</AccordionContent>
</AccordionItem>
</Accordion>
Expand Down
2 changes: 1 addition & 1 deletion packages/stack-shared/src/interface/crud/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const emailConfigSchema = yupObject({
});

const domainSchema = yupObject({
domain: schemaFields.projectTrustedDomainSchema.defined(),
TheCactusBlue marked this conversation as resolved.
Show resolved Hide resolved
domain: schemaFields.urlSchema.defined(),
TheCactusBlue marked this conversation as resolved.
Show resolved Hide resolved
handler_path: schemaFields.handlerPathSchema.defined(),
});

Expand Down