fix: fqdn or expose port required

This commit is contained in:
Andras Bacsai 2022-09-05 09:09:32 +02:00
parent eb26787079
commit dbd16e8285
4 changed files with 86 additions and 40 deletions

View File

@ -500,11 +500,15 @@ export async function checkDomain(request: FastifyRequest<CheckDomain>) {
} }
export async function checkDNS(request: FastifyRequest<CheckDNS>) { export async function checkDNS(request: FastifyRequest<CheckDNS>) {
try { try {
const { id } = request.params const { id } = request.params
let { exposePort, fqdn, forceSave, dualCerts } = request.body let { exposePort, fqdn, forceSave, dualCerts } = request.body
if (!fqdn) {
if (fqdn) fqdn = fqdn.toLowerCase(); return {}
} else {
fqdn = fqdn.toLowerCase();
}
if (exposePort) exposePort = Number(exposePort); if (exposePort) exposePort = Number(exposePort);
const { destinationDocker: { id: dockerId, remoteIpAddress, remoteEngine }, exposePort: configuredPort } = await prisma.application.findUnique({ where: { id }, include: { destinationDocker: true } }) const { destinationDocker: { id: dockerId, remoteIpAddress, remoteEngine }, exposePort: configuredPort } = await prisma.application.findUnique({ where: { id }, include: { destinationDocker: true } })

View File

@ -45,6 +45,17 @@ export const appSession: Writable<AppSession> = writable({
supportedServiceTypesAndVersions: [] supportedServiceTypesAndVersions: []
}); });
export const disabledButton: Writable<boolean> = writable(false); export const disabledButton: Writable<boolean> = writable(false);
export const isDeploymentEnabled: Writable<boolean> = writable(false);
export function checkIfDeploymentEnabledApplications(isAdmin: boolean, application: any) {
return (
isAdmin &&
(application.fqdn || (application.settings.isBot && application.exposePort)) &&
application.gitSource &&
application.repository &&
application.destinationDocker &&
application.buildPack
);
}
export const status: Writable<any> = writable({ export const status: Writable<any> = writable({
application: { application: {
isRunning: false, isRunning: false,

View File

@ -60,23 +60,26 @@
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { onDestroy, onMount } from 'svelte'; import { onDestroy, onMount } from 'svelte';
import { t } from '$lib/translations'; import { t } from '$lib/translations';
import { appSession, disabledButton, status, location, setLocation, addToast } from '$lib/store'; import {
appSession,
status,
location,
setLocation,
addToast,
isDeploymentEnabled,
checkIfDeploymentEnabledApplications
} from '$lib/store';
import { errorNotification, handlerNotFoundLoad } from '$lib/common'; import { errorNotification, handlerNotFoundLoad } from '$lib/common';
import Tooltip from '$lib/components/Tooltip.svelte'; import Tooltip from '$lib/components/Tooltip.svelte';
let statusInterval: any; let statusInterval: any;
let forceDelete = false; let forceDelete = false;
$disabledButton =
!$appSession.isAdmin ||
(!application.fqdn && !application.settings.isBot) ||
!application.gitSource ||
!application.repository ||
!application.destinationDocker ||
!application.buildPack;
const { id } = $page.params; const { id } = $page.params;
$isDeploymentEnabled = checkIfDeploymentEnabledApplications($appSession.isAdmin, application);
async function handleDeploySubmit(forceRebuild = false) { async function handleDeploySubmit(forceRebuild = false) {
if (!$isDeploymentEnabled) return;
try { try {
const { buildId } = await post(`/applications/${id}/deploy`, { const { buildId } = await post(`/applications/${id}/deploy`, {
...application, ...application,
@ -214,7 +217,7 @@
{#if $status.application.isExited} {#if $status.application.isExited}
<a <a
id="applicationerror" id="applicationerror"
href={!$disabledButton ? `/applications/${id}/logs` : null} href={$isDeploymentEnabled ? `/applications/${id}/logs` : null}
class="icons bg-transparent text-sm flex items-center text-error" class="icons bg-transparent text-sm flex items-center text-error"
sveltekit:prefetch sveltekit:prefetch
> >
@ -266,7 +269,7 @@
id="stop" id="stop"
on:click={stopApplication} on:click={stopApplication}
type="submit" type="submit"
disabled={$disabledButton} disabled={!$isDeploymentEnabled}
class="icons bg-transparent text-sm flex items-center space-x-2 text-error" class="icons bg-transparent text-sm flex items-center space-x-2 text-error"
> >
<svg <svg
@ -290,7 +293,7 @@
id="restart" id="restart"
on:click={restartApplication} on:click={restartApplication}
type="submit" type="submit"
disabled={$disabledButton} disabled={!$isDeploymentEnabled}
class="icons bg-transparent text-sm flex items-center space-x-2" class="icons bg-transparent text-sm flex items-center space-x-2"
> >
<svg <svg
@ -314,7 +317,7 @@
<button <button
id="forceredeploy" id="forceredeploy"
type="submit" type="submit"
disabled={$disabledButton} disabled={!$isDeploymentEnabled}
class="icons bg-transparent text-sm flex items-center space-x-2" class="icons bg-transparent text-sm flex items-center space-x-2"
> >
<svg <svg
@ -341,7 +344,7 @@
<button <button
id="deploy" id="deploy"
type="submit" type="submit"
disabled={$disabledButton} disabled={!$isDeploymentEnabled}
class="icons bg-transparent text-sm flex items-center space-x-2 text-success" class="icons bg-transparent text-sm flex items-center space-x-2 text-success"
> >
<svg <svg
@ -364,14 +367,17 @@
<div class="border border-coolgray-500 h-8" /> <div class="border border-coolgray-500 h-8" />
<a <a
id="configurations" href={$isDeploymentEnabled ? `/applications/${id}` : null}
href={!$disabledButton ? `/applications/${id}` : null}
sveltekit:prefetch sveltekit:prefetch
class="hover:text-yellow-500 rounded" class="hover:text-yellow-500 rounded"
class:text-yellow-500={$page.url.pathname === `/applications/${id}`} class:text-yellow-500={$page.url.pathname === `/applications/${id}`}
class:bg-coolgray-500={$page.url.pathname === `/applications/${id}`} class:bg-coolgray-500={$page.url.pathname === `/applications/${id}`}
> >
<button disabled={$disabledButton} class="icons bg-transparent text-sm"> <button
disabled={!$isDeploymentEnabled}
id="configurations"
class="icons bg-transparent text-sm"
>
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6" class="h-6 w-6"
@ -396,14 +402,13 @@
></a ></a
> >
<a <a
id="secrets" href={$isDeploymentEnabled ? `/applications/${id}/secrets` : null}
href={!$disabledButton ? `/applications/${id}/secrets` : null}
sveltekit:prefetch sveltekit:prefetch
class="hover:text-pink-500 rounded" class="hover:text-pink-500 rounded"
class:text-pink-500={$page.url.pathname === `/applications/${id}/secrets`} class:text-pink-500={$page.url.pathname === `/applications/${id}/secrets`}
class:bg-coolgray-500={$page.url.pathname === `/applications/${id}/secrets`} class:bg-coolgray-500={$page.url.pathname === `/applications/${id}/secrets`}
> >
<button disabled={$disabledButton} class="icons bg-transparent text-sm"> <button id="secrets" disabled={!$isDeploymentEnabled} class="icons bg-transparent text-sm">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6" class="w-6 h-6"
@ -424,14 +429,17 @@
></a ></a
> >
<a <a
id="persistentstorages" href={$isDeploymentEnabled ? `/applications/${id}/storages` : null}
href={!$disabledButton ? `/applications/${id}/storages` : null}
sveltekit:prefetch sveltekit:prefetch
class="hover:text-pink-500 rounded" class="hover:text-pink-500 rounded"
class:text-pink-500={$page.url.pathname === `/applications/${id}/storages`} class:text-pink-500={$page.url.pathname === `/applications/${id}/storages`}
class:bg-coolgray-500={$page.url.pathname === `/applications/${id}/storages`} class:bg-coolgray-500={$page.url.pathname === `/applications/${id}/storages`}
> >
<button disabled={$disabledButton} class="icons bg-transparent text-sm"> <button
id="persistentstorages"
disabled={!$isDeploymentEnabled}
class="icons bg-transparent text-sm"
>
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6" class="w-6 h-6"
@ -451,14 +459,13 @@
> >
{#if !application.settings.isBot} {#if !application.settings.isBot}
<a <a
id="previews" href={$isDeploymentEnabled ? `/applications/${id}/previews` : null}
href={!$disabledButton ? `/applications/${id}/previews` : null}
sveltekit:prefetch sveltekit:prefetch
class="hover:text-orange-500 rounded" class="hover:text-orange-500 rounded"
class:text-orange-500={$page.url.pathname === `/applications/${id}/previews`} class:text-orange-500={$page.url.pathname === `/applications/${id}/previews`}
class:bg-coolgray-500={$page.url.pathname === `/applications/${id}/previews`} class:bg-coolgray-500={$page.url.pathname === `/applications/${id}/previews`}
> >
<button disabled={$disabledButton} class="icons bg-transparent text-sm"> <button id="previews" disabled={!$isDeploymentEnabled} class="icons bg-transparent text-sm">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6" class="w-6 h-6"
@ -481,15 +488,15 @@
{/if} {/if}
<div class="border border-coolgray-500 h-8" /> <div class="border border-coolgray-500 h-8" />
<a <a
id="applicationlogs" href={$isDeploymentEnabled && $status.application.isRunning ? `/applications/${id}/logs` : null}
href={!$disabledButton && $status.application.isRunning ? `/applications/${id}/logs` : null}
sveltekit:prefetch sveltekit:prefetch
class="hover:text-sky-500 rounded" class="hover:text-sky-500 rounded"
class:text-sky-500={$page.url.pathname === `/applications/${id}/logs`} class:text-sky-500={$page.url.pathname === `/applications/${id}/logs`}
class:bg-coolgray-500={$page.url.pathname === `/applications/${id}/logs`} class:bg-coolgray-500={$page.url.pathname === `/applications/${id}/logs`}
> >
<button <button
disabled={$disabledButton || !$status.application.isRunning} id="applicationlogs"
disabled={!$isDeploymentEnabled || !$status.application.isRunning}
class="icons bg-transparent text-sm" class="icons bg-transparent text-sm"
> >
<svg <svg
@ -512,14 +519,13 @@
</button></a </button></a
> >
<a <a
id="buildlogs" href={$isDeploymentEnabled ? `/applications/${id}/logs/build` : null}
href={!$disabledButton ? `/applications/${id}/logs/build` : null}
sveltekit:prefetch sveltekit:prefetch
class="hover:text-red-500 rounded" class="hover:text-red-500 rounded"
class:text-red-500={$page.url.pathname === `/applications/${id}/logs/build`} class:text-red-500={$page.url.pathname === `/applications/${id}/logs/build`}
class:bg-coolgray-500={$page.url.pathname === `/applications/${id}/logs/build`} class:bg-coolgray-500={$page.url.pathname === `/applications/${id}/logs/build`}
> >
<button disabled={$disabledButton} class="icons bg-transparent text-sm"> <button id="buildlogs" disabled={!$isDeploymentEnabled} class="icons bg-transparent text-sm">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6" class="h-6 w-6"

View File

@ -34,7 +34,14 @@
import { get, post } from '$lib/api'; import { get, post } from '$lib/api';
import cuid from 'cuid'; import cuid from 'cuid';
import { addToast, appSession, disabledButton, setLocation, status } from '$lib/store'; import {
addToast,
appSession,
checkIfDeploymentEnabledApplications,
setLocation,
status,
isDeploymentEnabled
} from '$lib/store';
import { t } from '$lib/translations'; import { t } from '$lib/translations';
import { errorNotification, getDomain, notNodeDeployments, staticDeployments } from '$lib/common'; import { errorNotification, getDomain, notNodeDeployments, staticDeployments } from '$lib/common';
import Setting from '$lib/components/Setting.svelte'; import Setting from '$lib/components/Setting.svelte';
@ -64,6 +71,7 @@
let dualCerts = application.settings.dualCerts; let dualCerts = application.settings.dualCerts;
let autodeploy = application.settings.autodeploy; let autodeploy = application.settings.autodeploy;
let isBot = application.settings.isBot; let isBot = application.settings.isBot;
let isDBBranching = application.settings.isDBBranching;
let nonWWWDomain = application.fqdn && getDomain(application.fqdn).replace(/^www\./, ''); let nonWWWDomain = application.fqdn && getDomain(application.fqdn).replace(/^www\./, '');
let isNonWWWDomainOK = false; let isNonWWWDomainOK = false;
@ -162,6 +170,10 @@
application.settings.isBot = isBot; application.settings.isBot = isBot;
setLocation(application, settings); setLocation(application, settings);
} }
if (name === 'isDBBranching') {
isDBBranching = !isDBBranching;
application.settings.isDBBranching = isDBBranching;
}
try { try {
await post(`/applications/${id}/settings`, { await post(`/applications/${id}/settings`, {
previews, previews,
@ -193,13 +205,15 @@
isBot = !isBot; isBot = !isBot;
} }
return errorNotification(error); return errorNotification(error);
} finally {
$isDeploymentEnabled = checkIfDeploymentEnabledApplications($appSession.isAdmin, application);
} }
} }
async function handleSubmit() { async function handleSubmit() {
if (loading || (!application.fqdn && !isBot)) return; if (loading) return;
loading = true; loading = true;
try { try {
nonWWWDomain = application.fqdn && getDomain(application.fqdn).replace(/^www\./, ''); nonWWWDomain = application.fqdn != null && getDomain(application.fqdn).replace(/^www\./, '');
if (application.deploymentType) if (application.deploymentType)
application.deploymentType = application.deploymentType.toLowerCase(); application.deploymentType = application.deploymentType.toLowerCase();
!isBot && !isBot &&
@ -211,8 +225,10 @@
})); }));
await post(`/applications/${id}`, { ...application }); await post(`/applications/${id}`, { ...application });
setLocation(application, settings); setLocation(application, settings);
$disabledButton = false; $isDeploymentEnabled = checkIfDeploymentEnabledApplications($appSession.isAdmin, application);
forceSave = false; forceSave = false;
addToast({ addToast({
message: 'Configuration saved.', message: 'Configuration saved.',
type: 'success' type: 'success'
@ -551,7 +567,6 @@
disabled={isDisabled} disabled={isDisabled}
name="fqdn" name="fqdn"
id="fqdn" id="fqdn"
required
bind:value={application.fqdn} bind:value={application.fqdn}
pattern="^https?://([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{'{'}2,{'}'}$" pattern="^https?://([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{'{'}2,{'}'}$"
placeholder="eg: https://coollabs.io" placeholder="eg: https://coollabs.io"
@ -831,6 +846,16 @@
/> />
</div> </div>
{/if} {/if}
<div class="grid grid-cols-2 items-center">
<Setting
id="isDBBranching"
isCenter={false}
bind:setting={isDBBranching}
on:click={() => changeSettings('isDBBranching')}
title="Enable DB Branching"
description="Enable DB Branching"
/>
</div>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<Setting <Setting
id="debug" id="debug"