Skip to content

Commit

Permalink
add portainer url parsing
Browse files Browse the repository at this point in the history
fix for #7
  • Loading branch information
craftycram committed Apr 29, 2024
1 parent deb0ad6 commit c27ffc7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function getStacks(): Promise<Record<string, unknown>> {
reject: (error: Error) => void,
): void => {
axios
.get(`${process.env.PORTAINER_URL}/api/stacks`)
.get(new URL('/api/stacks', process.env.PORTAINER_URL).href)
.then((stacksRequest: any): void => {
if (!stacksRequest.data || !stacksRequest.data.length) {
reject(new Error('NO_STACKS_FOUND'));
Expand All @@ -70,7 +70,7 @@ function getStackFile(id: string): Promise<string> {
reject: (error: Error) => void,
): void => {
axios
.get(`${process.env.PORTAINER_URL}/api/stacks/${id}/file`)
.get(new URL(`/api/stacks/${id}/file`, process.env.PORTAINER_URL).href)
.then((stackFileRequest: any): void => {
if (
!stackFileRequest.data ||
Expand All @@ -93,7 +93,10 @@ function updateStack(stackUpdate: Record<string, any>): Promise<void> {
(resolve: (result: void) => void, reject: (error: Error) => void): void => {
axios
.put(
`${process.env.PORTAINER_URL}/api/stacks/${stackUpdate.stack.Id}?endpointId=${stackUpdate.stack.EndpointId}`,
new URL(
`/api/stacks/${stackUpdate.stack.Id}?endpointId=${stackUpdate.stack.EndpointId}`,
process.env.PORTAINER_URL,
).href,
{
stackFileContent: stackUpdate.compose,
env: stackUpdate.stack.Env,
Expand Down

0 comments on commit c27ffc7

Please sign in to comment.