Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,19 @@ export async function clientAction({ request, params }: Route.ClientActionArgs)
invariant(typeof patch.name === 'string', 'Name is required');
invariant(patch.name.startsWith('/'), 'Path must begin with a /');

const mockServer = await services.mockServer.getById(mockRoute.parentId);
const existingRoutes = await services.mockRoute.findByParentId(mockRoute.parentId);

if (mockServer?.useInsomniaCloud) {
const hasRouteInServer = existingRoutes.filter(m => m._id !== mockRouteId).find(m => m.name === patch.name);
if (hasRouteInServer) {
invariant(false, `Path "${patch.name}" already exists. Please enter a different path.`);
}
} else {
const hasRouteInServer = existingRoutes
.filter(m => m._id !== mockRouteId)
.find(
m => m.name === patch.name && m.method.toUpperCase() === (patch.method || mockRoute.method).toUpperCase(),
);
const hasRouteInServer = existingRoutes
.filter(m => m._id !== mockRouteId)
.find(
m => m.name === patch.name && m.method.toUpperCase() === (patch.method || mockRoute.method).toUpperCase(),
);

if (hasRouteInServer) {
invariant(
false,
`Path "${patch.name}" with ${patch.method || mockRoute.method} method already exists. Please enter a different path or method.`,
);
}
if (hasRouteInServer) {
invariant(
false,
`Path "${patch.name}" with ${patch.method || mockRoute.method} method already exists. Please enter a different path or method.`,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,16 @@ export async function clientAction({ request, params }: Route.ClientActionArgs)
invariant(patch.name.startsWith('/'), 'Path must begin with a /');

if (patch.parentId) {
const mockServer = await services.mockServer.getById(patch.parentId);
const existingRoutes = await services.mockRoute.findByParentId(patch.parentId);

if (mockServer?.useInsomniaCloud) {
const hasRouteInServer = existingRoutes.find(m => m.name === patch.name);
if (hasRouteInServer) {
invariant(false, `Path "${patch.name}" already exists. Please enter a different path.`);
}
} else {
const hasRouteInServer = existingRoutes.find(
m => m.name === patch.name && m.method.toUpperCase() === patch.method?.toUpperCase(),
const hasRouteInServer = existingRoutes.find(
m => m.name === patch.name && m.method.toUpperCase() === patch.method?.toUpperCase(),
);
if (hasRouteInServer) {
invariant(
false,
`Path "${patch.name}" with ${patch.method} method already exists. Please enter a different path or method.`,
);
if (hasRouteInServer) {
invariant(
false,
`Path "${patch.name}" with ${patch.method} method already exists. Please enter a different path or method.`,
);
}
}
}
// TODO: remove this hack which enables a mock server to be created alongside a route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ export const NewWorkspaceModal = ({
setWorkspaceData({
...workspaceData,
mockServerCreationType: creationType as 'ai' | 'manual',
mockServerType: creationType === 'ai' ? 'self-hosted' : workspaceData.mockServerType,
});
}}
className="mb-2 flex flex-col gap-2"
Expand Down Expand Up @@ -628,19 +627,17 @@ export const NewWorkspaceModal = ({
<div className="flex gap-2">
<Radio
value="cloud"
isDisabled={isCloudMockDisabled || workspaceData.mockServerCreationType === 'ai'}
isDisabled={isCloudMockDisabled}
className="flex-1 rounded-sm border border-solid border-(--hl-md) p-4 transition-colors hover:bg-(--hl-xs) focus:bg-(--hl-sm) focus:outline-hidden data-disabled:opacity-25 data-selected:border-(--color-surprise) data-selected:ring-2 data-selected:ring-(--color-surprise)"
>
<div className="flex items-center gap-2">
<Icon icon="globe" />
<Heading className="text-lg font-bold">Cloud Mock</Heading>
</div>
<p className="pt-2">
{workspaceData.mockServerCreationType === 'ai'
? 'Not available when creating with Auto Generate.'
: isCloudMockDisabled
? 'Only available for cloud projects'
: 'Runs on Insomnia cloud, ideal for collaboration.'}
{isCloudMockDisabled
? 'Only available for cloud projects'
: 'Runs on Insomnia cloud, ideal for collaboration.'}
</p>
</Radio>
<Radio
Expand Down
Loading