From 17b4d020e79c540ce1f4e1b8f357d8b98a7adbc9 Mon Sep 17 00:00:00 2001
From: Angelo Reale <12191809+angeloreale@users.noreply.github.com>
Date: Thu, 8 Aug 2024 22:19:44 +0100
Subject: [PATCH] ar(fix) [DPTM-2] [DPCP-78]: Ensure autonomous Dev environment
(#35) (#36)
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment (#35)
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* [DPTM-2] Dev env (#37)
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* [DPTM-2] dev env (#38)
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* [DPTM-2]: dev env (#39)
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
---------
Signed-off-by: Angelo Reale <12191809+angeloreale@users.noreply.github.com>
* [DPTM-2]: dev env (#40)
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
---------
Signed-off-by: Angelo Reale <12191809+angeloreale@users.noreply.github.com>
---------
Signed-off-by: Angelo Reale <12191809+angeloreale@users.noreply.github.com>
---
.env.public | 4 +++-
README.md | 3 ++-
lib/auth/constants.ts | 6 +++---
next.config.js | 7 ++++++-
src/app/components/client/elements/link-decorator.tsx | 2 +-
src/middleware.ts | 11 +++++++++++
6 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/.env.public b/.env.public
index 35595232..16c37935 100644
--- a/.env.public
+++ b/.env.public
@@ -10,6 +10,8 @@
# env specific
API_HOST_DEV=
API_HOST=http://localhost:3001
+NEXUS_HOST=http://localhost:3000
+MAIN_URL=http://localhost:2999
# context specific
GITHUB_ID=
@@ -48,7 +50,7 @@ MONGODB_DEFAULT_ORG=yourorg
# @@@ WARNING: THESE APPEAR IN THE BROWSER OF EVERY VISITOR @@@
# base path: client (browser)
-NEXT_PUBLIC_NEXUS_HOST=
+NEXT_PUBLIC_MAIN_URL=http://localhost:2999
NEXT_PUBLIC_NEXUS_BASE_PATH=
NEXT_PUBLIC_NEXUS_NAME=Nexus
NEXT_PUBLIC_NEXUS_LOGO_PATH=
diff --git a/README.md b/README.md
index 869398a5..e8d3e2b8 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,8 @@ npm run dev
Documentation: TBD
-Staging Environment: https://alpha.dreampip.com
+Dev Environment: https://dev.nyx.dreampip.com
+Prod Environment: https://nyx.dreampip.com
License: HPL3-ECO-AND-ANC 2021—Present
diff --git a/lib/auth/constants.ts b/lib/auth/constants.ts
index 6c4ff121..5f5fe18a 100644
--- a/lib/auth/constants.ts
+++ b/lib/auth/constants.ts
@@ -11,7 +11,7 @@ const methods = {
signIn: () => {},
signOut: async () => {
try {
- const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/v1/auth/signout`, {
+ const response = await fetch(`${process.env.NEXT_PUBLIC_MAIN_URL}/api/v1/auth/signout`, {
method: 'POST',
headers: {
Accept: 'application/json',
@@ -26,7 +26,7 @@ const methods = {
},
getCsrf: async () => {
try {
- const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/v1/auth/csrf`, {
+ const response = await fetch(`${process.env.NEXT_PUBLIC_MAIN_URL}/api/v1/auth/csrf`, {
method: 'GET',
headers: {
Accept: 'application/json',
@@ -41,7 +41,7 @@ const methods = {
},
getSession: async (params = { cookies: '' }) => {
try {
- const response = await fetch(`${process.env.NEXT_PUBLIC_NEXUS_HOST}/api/v1/auth/session`, {
+ const response = await fetch(`${process.env.NEXT_PUBLIC_MAIN_URL}/api/v1/auth/session`, {
method: 'GET',
headers: {
Accept: 'application/json',
diff --git a/next.config.js b/next.config.js
index 212f38ae..92e254d8 100644
--- a/next.config.js
+++ b/next.config.js
@@ -1,7 +1,7 @@
/** @type {import('next').NextConfig} */
const { withSentryConfig } = require('@sentry/nextjs');
const nextConfig = {
- assetPrefix: process.env.MAIN_URL || 'https://nyx.dreampip.com',
+ assetPrefix: process.env.NEXUS_HOST || 'https://nyx.dreampip.com',
transpilePackages: ['next-auth'],
images: {
remotePatterns: [
@@ -11,6 +11,11 @@ const nextConfig = {
},
],
},
+ experimental: {
+ serverActions: {
+ allowedOrigins: ['dreampip.com', '*.dreampip.com'],
+ },
+ },
async redirects() {
return [
{
diff --git a/src/app/components/client/elements/link-decorator.tsx b/src/app/components/client/elements/link-decorator.tsx
index 95d9e7c8..04bac103 100644
--- a/src/app/components/client/elements/link-decorator.tsx
+++ b/src/app/components/client/elements/link-decorator.tsx
@@ -4,6 +4,6 @@ import { Link as DPLink } from "@dreampipcom/oneiros"
export const DPLinkDec = (props: any) => {
return (
-
+
);
};
diff --git a/src/middleware.ts b/src/middleware.ts
index 7ccf4cc5..532acf15 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -6,6 +6,12 @@ export const config = {
matcher: ['/api/:path*'],
};
+const allowedOrigins = {
+ [`${process.env.MAIN_URL}`]: process.env.MAIN_URL,
+ [`${process.env.NEXUS_HOST}`]: process.env.NEXUS_HOST,
+ [`${process.env.API_HOST}`]: process.env.API_HOST,
+};
+
const headers: Record = {
'Access-Control-Allow-Origin': process.env.MAIN_URL || 'https://www.dreampip.com',
'Cache-Control': 'maxage=0, s-maxage=300, stale-while-revalidate=300',
@@ -17,6 +23,11 @@ const headers: Record = {
};
export function middleware(request: NextRequest) {
+ const origin = request.headers.get('x-forwarded-host') || '';
+ if (origin !== process.env.MAIN_URL) {
+ headers['Access-Control-Allow-Origin'] = allowedOrigins[origin] || 'https://www.dreampip.com';
+ }
+
const response = NextResponse.next();
const pkce = request.cookies.get('next-auth.pkce.code_verifier');