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

[chore] Updated web and deploy backend configuration for reverse proxy & decoupled Plane Deploy URL generation for web #2135

Merged
merged 13 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ services:
dockerfile: ./web/Dockerfile.web
args:
DOCKER_BUILDKIT: 1
NEXT_PUBLIC_API_BASE_URL: "http://localhost:8000"
restart: always
command: /usr/local/bin/start.sh web/server.js web
depends_on:
Expand All @@ -22,7 +21,6 @@ services:
dockerfile: ./space/Dockerfile.space
args:
DOCKER_BUILDKIT: 1
NEXT_PUBLIC_API_BASE_URL: http://localhost:8000
restart: always
command: /usr/local/bin/start.sh space/server.js space
depends_on:
Expand Down Expand Up @@ -87,6 +85,9 @@ services:
env_file:
- .env
environment:
POSTGRES_USER: ${PGUSER}
POSTGRES_DB: ${PGDATABASE}
POSTGRES_PASSWORD: ${PGPASSWORD}
PGDATA: /var/lib/postgresql/data

plane-redis:
Expand Down
9 changes: 7 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ cp ./apiserver/.env.example ./apiserver/.env
# Generate the SECRET_KEY that will be used by django
echo -e "SECRET_KEY=\"$(tr -dc 'a-z0-9' < /dev/urandom | head -c50)\"" >> ./apiserver/.env

echo -e "\nNEXT_PUBLIC_API_BASE_URL=$1\nWEB_URL=$1" >> ./web/.env
echo -e "\nNEXT_PUBLIC_API_BASE_URL=$1\nWEB_URL=$1" >> ./space/.env
if [ -n "$1" ]
then
echo "hello"
Copy link
Contributor

@sriramveeraghanta sriramveeraghanta Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove hello

echo -e "\nNEXT_PUBLIC_API_BASE_URL=$1\nWEB_URL=$1" >> ./web/.env
echo -e "\nNEXT_PUBLIC_API_BASE_URL=$1\nWEB_URL=$1" >> ./space/.env
fi


# Generate Prompt for taking tiptap auth key
echo -e "\n\e[1;38m Instructions for generating TipTap Pro Extensions Auth Token \e[0m \n"
Expand Down
4 changes: 2 additions & 2 deletions space/Dockerfile.space
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
USER root

ARG NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
ARG NEXT_PUBLIC_API_BASE_URL=""
ARG NEXT_PUBLIC_DEPLOY_WITH_NGINX=1

ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
Expand All @@ -44,7 +44,7 @@ COPY --from=installer --chown=captain:plane /app/space/.next/standalone ./
COPY --from=installer --chown=captain:plane /app/space/.next ./space/.next
COPY --from=installer --chown=captain:plane /app/space/public ./space/public

ARG NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
ARG NEXT_PUBLIC_API_BASE_URL=""
ARG NEXT_PUBLIC_DEPLOY_WITH_NGINX=1

ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
Expand Down
2 changes: 2 additions & 0 deletions space/helpers/common.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const API_BASE_URL =
process.env.NEXT_PUBLIC_API_BASE_URL !== undefined ? process.env.NEXT_PUBLIC_API_BASE_URL : "http://localhost:8000";
3 changes: 2 additions & 1 deletion space/services/authentication.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// services
import APIService from "services/api.service";
import { API_BASE_URL } from "helpers/common.helper";

class AuthService extends APIService {
constructor() {
super(process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async emailLogin(data: any) {
Expand Down
6 changes: 2 additions & 4 deletions space/services/file.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// services
import APIService from "services/api.service";

const { NEXT_PUBLIC_API_BASE_URL } = process.env;
import { API_BASE_URL } from "helpers/common.helper";

interface UnSplashImage {
id: string;
Expand Down Expand Up @@ -29,7 +27,7 @@ interface UnSplashImageUrls {

class FileServices extends APIService {
constructor() {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async uploadFile(workspaceSlug: string, file: FormData): Promise<any> {
Expand Down
3 changes: 2 additions & 1 deletion space/services/issue.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// services
import APIService from "services/api.service";
import { API_BASE_URL } from "helpers/common.helper";

class IssueService extends APIService {
constructor() {
super(process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async getPublicIssues(workspace_slug: string, project_slug: string, params: any): Promise<any> {
Expand Down
3 changes: 2 additions & 1 deletion space/services/project.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// services
import APIService from "services/api.service";
import { API_BASE_URL } from "helpers/common.helper";

class ProjectService extends APIService {
constructor() {
super(process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async getProjectSettings(workspace_slug: string, project_slug: string): Promise<any> {
Expand Down
3 changes: 2 additions & 1 deletion space/services/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// services
import APIService from "services/api.service";
import { API_BASE_URL } from "helpers/common.helper";

class UserService extends APIService {
constructor() {
super(process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async currentUser(): Promise<any> {
Expand Down
2 changes: 1 addition & 1 deletion web/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ NEXT_PUBLIC_SLACK_CLIENT_ID=""
# For Telemetry, set it to "app.plane.so"
NEXT_PUBLIC_PLAUSIBLE_DOMAIN=""
# Public boards deploy URL
NEXT_PUBLIC_DEPLOY_URL=""
NEXT_PUBLIC_DEPLOY_URL="http://localhost:3000/spaces"
8 changes: 6 additions & 2 deletions web/Dockerfile.web
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ FROM node:18-alpine AS installer

RUN apk add --no-cache libc6-compat
WORKDIR /app
ARG NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
ARG NEXT_PUBLIC_API_BASE_URL=""
ARG NEXT_PUBLIC_DEPLOY_URL=""

# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
Expand All @@ -26,6 +27,7 @@ COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
USER root
ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
ENV NEXT_PUBLIC_DEPLOY_URL=$NEXT_PUBLIC_DEPLOY_URL

RUN yarn turbo run build --filter=web

Expand All @@ -45,8 +47,10 @@ COPY --from=installer /app/web/package.json .
COPY --from=installer --chown=captain:plane /app/web/.next/standalone ./
COPY --from=installer --chown=captain:plane /app/web/.next ./web/.next

ARG NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
ARG NEXT_PUBLIC_API_BASE_URL=""
ARG NEXT_PUBLIC_DEPLOY_URL=""
ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
ENV NEXT_PUBLIC_DEPLOY_URL=$NEXT_PUBLIC_DEPLOY_URL

USER root
COPY start.sh /usr/local/bin/
Expand Down
6 changes: 5 additions & 1 deletion web/components/project/publish-project/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export const PublishProjectModal: React.FC<Props> = observer(() => {
const [isUnpublishing, setIsUnpublishing] = useState(false);
const [isUpdateRequired, setIsUpdateRequired] = useState(false);

const plane_deploy_url = process.env.NEXT_PUBLIC_DEPLOY_URL ?? "http://localhost:4000";
let plane_deploy_url = process.env.NEXT_PUBLIC_DEPLOY_URL;

if (typeof window !== 'undefined' && !plane_deploy_url) {
plane_deploy_url= window.location.protocol + "//" + window.location.host + "/spaces";
}

const router = useRouter();
const { workspaceSlug } = router.query;
Expand Down
5 changes: 5 additions & 0 deletions web/helpers/common.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ export const debounce = (func: any, wait: number, immediate: boolean = false) =>
if (callNow) func(...args);
};
};

export const API_BASE_URL =
process.env.NEXT_PUBLIC_API_BASE_URL !== undefined
? process.env.NEXT_PUBLIC_API_BASE_URL
: "http://localhost:8000";
6 changes: 5 additions & 1 deletion web/layouts/app-layout/app-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ type Props = {
};

const { NEXT_PUBLIC_DEPLOY_URL } = process.env;
const plane_deploy_url = NEXT_PUBLIC_DEPLOY_URL ? NEXT_PUBLIC_DEPLOY_URL : "http://localhost:3001";
let plane_deploy_url = NEXT_PUBLIC_DEPLOY_URL

if (typeof window !== 'undefined' && !plane_deploy_url) {
plane_deploy_url= window.location.protocol + "//" + window.location.host + "/spaces";
}

const Header: React.FC<Props> = ({ breadcrumbs, left, right, setToggleSidebar, noHeader }) => {
const { projectDetails } = useProjectDetails();
Expand Down
33 changes: 15 additions & 18 deletions web/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
import { convertCookieStringToObject } from "./cookie";
// types
import type { IProjectMember, IUser, IWorkspace, IWorkspaceMember } from "types";
// helper
import { API_BASE_URL } from "helpers/common.helper";

export const requiredAuth = async (cookie?: string) => {
const cookies = convertCookieStringToObject(cookie);
const token = cookies?.accessToken;

if (!token) return null;

const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";

let user: IUser | null = null;

try {
const data = await fetch(`${baseUrl}/api/users/me/`, {
const data = await fetch(`${API_BASE_URL}/api/users/me/`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand All @@ -41,13 +41,11 @@ export const requiredAdmin = async (workspaceSlug: string, projectId: string, co
const cookies = convertCookieStringToObject(cookie);
const token = cookies?.accessToken;

const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";

let memberDetail: IProjectMember | null = null;

try {
const data = await fetch(
`${baseUrl}/api/workspaces/${workspaceSlug}/projects/${projectId}/project-members/me/`,
`${API_BASE_URL}/api/workspaces/${workspaceSlug}/projects/${projectId}/project-members/me/`,
{
method: "GET",
headers: {
Expand Down Expand Up @@ -75,17 +73,18 @@ export const requiredWorkspaceAdmin = async (workspaceSlug: string, cookie?: str
const cookies = convertCookieStringToObject(cookie);
const token = cookies?.accessToken;

const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";

let memberDetail: IWorkspaceMember | null = null;

try {
const data = await fetch(`${baseUrl}/api/workspaces/${workspaceSlug}/workspace-members/me/`, {
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
})
const data = await fetch(
`${API_BASE_URL}/api/workspaces/${workspaceSlug}/workspace-members/me/`,
{
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
}
)
.then((res) => res.json())
.then((data) => data);

Expand Down Expand Up @@ -119,13 +118,11 @@ export const homePageRedirect = async (cookie?: string) => {

let workspaces: IWorkspace[] = [];

const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";

const cookies = convertCookieStringToObject(cookie);
const token = cookies?.accessToken;

try {
const data = await fetch(`${baseUrl}/api/users/me/workspaces/`, {
const data = await fetch(`${API_BASE_URL}/api/users/me/workspaces/`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -166,7 +163,7 @@ export const homePageRedirect = async (cookie?: string) => {
};
}

const invitations = await fetch(`${baseUrl}/api/users/me/invitations/workspaces/`, {
const invitations = await fetch(`${API_BASE_URL}/api/users/me/invitations/workspaces/`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand Down
8 changes: 3 additions & 5 deletions web/services/ai.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// services
import APIService from "services/api.service";
import trackEventServices from "services/track-event.service";

// types
import { ICurrentUserResponse, IGptResponse } from "types";

const { NEXT_PUBLIC_API_BASE_URL } = process.env;
// helpers
import { API_BASE_URL } from "helpers/common.helper";

const trackEvent =
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";

class AiServices extends APIService {
constructor() {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async createGptTask(
Expand Down
5 changes: 2 additions & 3 deletions web/services/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import {
IExportAnalyticsFormData,
ISaveAnalyticsFormData,
} from "types";

const { NEXT_PUBLIC_API_BASE_URL } = process.env;
import { API_BASE_URL } from "helpers/common.helper";

class AnalyticsServices extends APIService {
constructor() {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async getAnalytics(workspaceSlug: string, params: IAnalyticsParams): Promise<IAnalyticsResponse> {
Expand Down
5 changes: 2 additions & 3 deletions web/services/app-installations.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// services
import axios from "axios";
import APIService from "services/api.service";

const { NEXT_PUBLIC_API_BASE_URL } = process.env;
import { API_BASE_URL } from "helpers/common.helper";

class AppInstallationsService extends APIService {
constructor() {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async addInstallationApp(workspaceSlug: string, provider: string, data: any): Promise<any> {
Expand Down
5 changes: 2 additions & 3 deletions web/services/authentication.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// services
import APIService from "services/api.service";
import { ICurrentUserResponse } from "types";

const { NEXT_PUBLIC_API_BASE_URL } = process.env;
import { API_BASE_URL } from "helpers/common.helper";

class AuthService extends APIService {
constructor() {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async emailLogin(data: any) {
Expand Down
6 changes: 2 additions & 4 deletions web/services/cycles.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// services
import APIService from "services/api.service";
import trackEventServices from "services/track-event.service";

// types
import type { CycleDateCheckData, ICurrentUserResponse, ICycle, IIssue } from "types";

const { NEXT_PUBLIC_API_BASE_URL } = process.env;
import { API_BASE_URL } from "helpers/common.helper";

const trackEvent =
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";

class ProjectCycleServices extends APIService {
constructor() {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async createCycle(
Expand Down
5 changes: 2 additions & 3 deletions web/services/estimates.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import APIService from "services/api.service";
// types
import type { ICurrentUserResponse, IEstimate, IEstimateFormData } from "types";
import trackEventServices from "services/track-event.service";

const { NEXT_PUBLIC_API_BASE_URL } = process.env;
import { API_BASE_URL } from "helpers/common.helper";

const trackEvent =
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";

class ProjectEstimateServices extends APIService {
constructor() {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
super(API_BASE_URL);
}

async createEstimate(
Expand Down
Loading
Loading