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

Update Map of Pi Repo with Changes Introduced on PCT-managed repo #13

Merged
merged 51 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f8e08e2
Initial commit
Aug 30, 2024
266f801
Merge branch 'staging' into 'main'
Aug 30, 2024
3a356b0
[REVERT-ME] Add hard-coded BACKEND_URL to FE for staging environment …
Sep 6, 2024
8f54c08
Change FE build output dir from app/dist to app/build
Sep 6, 2024
bb542a5
Merge remote-tracking branch 'gh/dev' into staging
Sep 6, 2024
2118b03
Specify paths of pm2 logfiles
Sep 6, 2024
e10fd58
Rename BE's config.js to ecosystem.config.js
Sep 7, 2024
ad7a08c
Add 'console' (actually file) logging to BE prod environment
Sep 7, 2024
bbec6e8
Run a server in all environments including prod
Sep 9, 2024
20b3a9d
Add env variable-based logging option
Sep 9, 2024
4e48f8e
Change BE Dockerfile exposed port to 80
Sep 9, 2024
99238ba
Update nginx version in Docker image
Sep 9, 2024
5dcb703
Expose port 80 for FE container
Sep 9, 2024
ee00364
Adjust MongoDB connection implementation to construct URL from its di…
Sep 9, 2024
b3beaa0
Update nginx to alpine version
Sep 10, 2024
c05ed5c
Adjust ngnix config to point to a valid index.html
Sep 10, 2024
d6183c3
Frontend variable files for different environments
Sep 11, 2024
4ae34fc
Set up frontend to be served directly from Node
Sep 12, 2024
670a0ca
Add temporary Sentry DSN for staging
Sep 12, 2024
3dfc303
Load Pi SDK dynamically
Sep 12, 2024
563ef09
Avoid redirecting when navigating to default locale on frontend
Sep 13, 2024
b3ee157
Make BACKEND_URL accessible to client for API calls
Sep 13, 2024
439caec
Use the official Pi SDK
Sep 14, 2024
9c2b7a5
Remove redundant import of Pi SDK
Sep 14, 2024
0b73f74
Attempt to resolve missing authentication in Pi Browser with deferred…
Sep 17, 2024
bb04cbb
Attempt to set up DigitalOcean connection for images
Sep 17, 2024
f16b160
[REVERT ME] Show SDK URL in search bar for debugging
Sep 17, 2024
8eaab0c
Revert "[REVERT ME] Show SDK URL in search bar for debugging"
Sep 17, 2024
a268d7d
Test whether AppContextProvider is loading in Pi Browser
Sep 17, 2024
88b74cb
FE Toasts whether user is present on AppContextProvider load
Sep 17, 2024
ed54deb
Add debugging toast to diagnose cause of no login on Pi Browser
Sep 17, 2024
059b537
Add toast calls to determine where registration code is crashing
Sep 17, 2024
9a4533d
Add toasts to see where error is being thrown in authentication flow
Sep 17, 2024
9153454
Remove debugging toasts
Sep 17, 2024
c278c14
Update DigitalOcean variables
Sep 17, 2024
cda5037
Correct error in BACKEND_URL environment variable
Sep 17, 2024
9843a47
Merge branch 'dev' of https://github.com/map-of-pi/map-of-pi-docker
Sep 19, 2024
1c255cd
Point FE Sentry to Map of Pi-managed Sentry project
Sep 20, 2024
8eedba7
Log messages of errors showing [object Object] on Sentry
Sep 20, 2024
f91f5e6
Merge branch 'dev' of https://github.com/map-of-pi/map-of-pi-docker
Sep 24, 2024
4cce1fe
Fix failing BE pods
Sep 24, 2024
54fb584
Dynamically load MapCenter component in Sidebar
Sep 24, 2024
f483c4e
Save image DigitalOcean link to seller record
Sep 25, 2024
98ae9e1
Upload images to DigitalOcean with correct Content-Type
Sep 25, 2024
452f144
Whitelist DigitalOcean bucket URL on FE for displaying images
Sep 26, 2024
2608ef0
Fix image uploads for reviews and userPreferences
Sep 27, 2024
b7d9da5
Change Sentry DSN to point to correct project
Sep 27, 2024
f2d31e8
[Housekeeping] Improve variable names for DigitalOcean credentials
Sep 27, 2024
621a107
Merge branch 'dev' of https://github.com/map-of-pi/map-of-pi-docker
Sep 27, 2024
296c267
Remove unused image upload files on BE
Sep 30, 2024
a1fc130
Remove cloudinary-related code from app
Oct 1, 2024
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
4 changes: 2 additions & 2 deletions backend/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ CLOUDINARY_CLOUD_NAME="ADD YOUR CLOUDINARY INFO"
CLOUDINARY_API_KEY="ADD YOUR CLOUDINARY INFO"
CLOUDINARY_API_SECRET="ADD YOUR CLOUDINARY INFO"

DIGITAL_OCEAN_KEY_ID=
DIGITAL_OCEAN_SECRET_ACCESS_KEY=
DIGITAL_OCEAN_BUCKET_ACCESS_KEY=
DIGITAL_OCEAN_BUCKET_SECRET_KEY=
DIGITAL_OCEAN_BUCKET_NAME=
DIGITAL_OCEAN_BUCKET_ORIGIN_ENDPOINT=
DIGITAL_OCEAN_BUCKET_CDN_ENDPOINT=
Expand Down
7 changes: 3 additions & 4 deletions backend/src/controllers/reviewFeedbackController.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Request, Response } from "express";

import * as reviewFeedbackService from "../services/reviewFeedback.service";
import { uploadImage } from "../services/misc/image.service";
import { IReviewFeedback } from "../types";

import { env } from "../utils/env";
import logger from "../config/loggingConfig";

export const getReviews = async (req: Request, res: Response) => {
Expand Down Expand Up @@ -56,9 +54,10 @@ export const addReview = async (req: Request, res: Response) => {
return res.status(400).json({ message: "Self review is prohibited" });
}

// image file handling
// image file handling (have to ts-ignore because tsc thinks the file can't have a location property, even though it can and does)
const file = req.file;
const image = file ? await uploadImage(authUser.pi_uid, file, 'review-feedback') : '';
//@ts-ignore
const image = file ? file.location : '';

const newReview = await reviewFeedbackService.addReviewFeedback(authUser, formData, image);
logger.info(`Added new review by user ${authUser.pi_uid} for receiver ID ${newReview.review_receiver_id}`);
Expand Down
9 changes: 3 additions & 6 deletions backend/src/controllers/sellerController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Request, Response } from "express";
import * as sellerService from "../services/seller.service";
import { uploadImage } from "../services/misc/image.service";

import logger from "../config/loggingConfig";
import { ISeller } from "../types";
Expand Down Expand Up @@ -76,11 +75,9 @@ export const registerSeller = async (req: Request, res: Response) => {
return res.status(401).json({ message: "Unauthorized user" });
}

// image file handling
const file = req.file;
const image = file ? await uploadImage(authUser.pi_uid, file, 'seller-registration') : '';

formData.image = image;
// image file handling (have to ts-ignore because tsc thinks the file can't have a location property, even though it can and does)
//@ts-ignore
const image = req.file ? req.file.location : '';

const registeredSeller = await sellerService.registerOrUpdateSeller(authUser, formData, image);
logger.info(`Registered or updated seller for user ${authUser.pi_uid}`);
Expand Down
6 changes: 3 additions & 3 deletions backend/src/controllers/userPreferencesController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Request, Response } from "express";

import * as userSettingsService from "../services/userSettings.service";
import { uploadImage } from "../services/misc/image.service";
import { IUserSettings } from "../types";

import logger from "../config/loggingConfig";
Expand Down Expand Up @@ -56,9 +55,10 @@ export const addUserPreferences = async (req: Request, res: Response) => {
return res.status(401).json({ message: "Unauthorized user" });
}

// image file handling
// image file handling (have to ts-ignore because tsc thinks the file can't have a location property, even though it can and does)
const file = req.file;
const image = file ? await uploadImage(authUser.pi_uid, file, 'user-preferences') : '';
//@ts-ignore
const image = file ? file.location : '';

const userPreferences = await userSettingsService.addOrUpdateUserSettings(authUser, formData, image);
logger.info(`Added or updated User Preferences for user with ID: ${authUser.pi_uid}`);
Expand Down
2 changes: 2 additions & 0 deletions backend/src/helpers/imageUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import cloudinary from "../utils/cloudinary";

import logger from '../config/loggingConfig';

// TODO: Is anything going to be done with this file or can it be removed?
// Seems to be redundant given the uploadImage method in image.service.ts
export const uploadMultipleImages = async (files: any) => {
try {
const uploadedImages = [];
Expand Down
1 change: 1 addition & 0 deletions backend/src/services/misc/image.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cloudinary from '../../utils/cloudinary';
import logger from '../../config/loggingConfig';

// TODO: should be able to remove this I think, since multer is handling the uploads to DigitalOcean on its own
export const uploadImage = async (publicId: string, file: Express.Multer.File, folder: string) => {
try {
const result = await cloudinary.uploader.upload(file.path, {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const env = {
JWT_SECRET: process.env.JWT_SECRET || 'default_secret',
DIGITAL_OCEAN_BUCKET_ORIGIN_ENDPOINT: process.env.DIGITAL_OCEAN_BUCKET_ORIGIN_ENDPOINT || '',
DIGITAL_OCEAN_BUCKET_CDN_ENDPOINT: process.env.DIGITAL_OCEAN_BUCKET_CDN_ENDPOINT || '',
DIGITAL_OCEAN_KEY_ID: process.env.DIGITAL_OCEAN_KEY_ID || '',
DIGITAL_OCEAN_SECRET_ACCESS_KEY: process.env.DIGITAL_OCEAN_SECRET_ACCESS_KEY || '',
DIGITAL_OCEAN_BUCKET_ACCESS_KEY: process.env.DIGITAL_OCEAN_BUCKET_ACCESS_KEY || '',
DIGITAL_OCEAN_BUCKET_SECRET_KEY: process.env.DIGITAL_OCEAN_BUCKET_SECRET_KEY || '',
DIGITAL_OCEAN_BUCKET_NAME: process.env.DIGITAL_OCEAN_BUCKET_NAME || '',
LOG_LEVEL: process.env.LOG_LEVEL || '',
PI_API_KEY: process.env.PI_API_KEY || '',
Expand Down
5 changes: 3 additions & 2 deletions backend/src/utils/multer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ const s3 = new S3({
endpoint: env.DIGITAL_OCEAN_BUCKET_ORIGIN_ENDPOINT,
region: "us-east-1",
credentials: {
accessKeyId: env.DIGITAL_OCEAN_KEY_ID,
secretAccessKey: env.DIGITAL_OCEAN_SECRET_ACCESS_KEY
accessKeyId: env.DIGITAL_OCEAN_BUCKET_ACCESS_KEY,
secretAccessKey: env.DIGITAL_OCEAN_BUCKET_SECRET_KEY
}
});

const storage = multerS3({
s3,
bucket: env.DIGITAL_OCEAN_BUCKET_NAME,
acl: 'public-read',
contentType: multerS3.AUTO_CONTENT_TYPE,
key: function (request: any, file: any, callback: any) {
callback(null, file.originalname);
}
Expand Down
2 changes: 1 addition & 1 deletion backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"rootDir": ".",
"rootDir": "./src",
"outDir": "./build",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand Down
1 change: 1 addition & 0 deletions frontend/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Your environment-specific values should be set in your .env.local file, which is not tracked in version control.

NODE_ENV=development
IMAGE_BUCKET_HOST=ADD-YOUR-IMAGE-HOST-HERE.com
NEXT_PUBLIC_BACKEND_URL=http://localhost:8001
NEXT_PUBLIC_IMAGE_PLACEHOLDER_URL="ADD YOUR IMAGE PLACEHOLDER URL"
NEXT_PUBLIC_SENTRY_DSN=https://e7a6a9d1d2ac4ab65091a8cb55535688@o4507779280732160.ingest.us.sentry.io/4507779383361536
Expand Down
3 changes: 2 additions & 1 deletion frontend/.env.staging
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NODE_ENV=production
IMAGE_BUCKET_HOST=mapofpi-staging.sfo3.digitaloceanspaces.com
NEXT_PUBLIC_BACKEND_URL=https://backend.mapofpi-heuwx64a8iqc29xo.staging.piappengine.com
NEXT_PUBLIC_SENTRY_DSN=https://b729b3a46999a192129cec0202930bba@o4507937361625088.ingest.us.sentry.io/4507937365819392
NEXT_PUBLIC_SENTRY_DSN=https://af0c1f20356a70c1ffedf8bdde40992a@o4507986464276480.ingest.us.sentry.io/4507986486362112
NEXT_PUBLIC_PI_SDK_URL=https://staging-sdk.socialchainapp.com/pi-sdk.js
16 changes: 9 additions & 7 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ const nextConfig = {
},
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'example.com',
port: '',
pathname: '/**',
},
// TODO: Can the bing and cloudinary patterns be removed now that we're using DigitalOcean? Might also be able to remove the
// localhost one as well
{
protocol: 'http',
hostname: 'localhost',
Expand All @@ -33,7 +29,13 @@ const nextConfig = {
hostname: 'res.cloudinary.com',
port: '',
pathname: '/**',
}
},
{
protocol: 'https',
hostname: process.env.IMAGE_BUCKET_HOST,
port: '',
pathname: '/**',
},
],
},
async rewrites() {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/shared/Review/emojipicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export default function EmojiPicker(props: any) {
logger.warn('Unable to submit review; user not authenticated.');
toast.error(t('SHARED.VALIDATION.SUBMISSION_FAILED_USER_NOT_AUTHENTICATED'));
}
} catch (error) {
logger.error('Error saving review:', { error });
} catch (error: any) {
logger.error('Error saving review:', { error: error?.message });
}
};

Expand Down
11 changes: 8 additions & 3 deletions frontend/src/components/shared/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import styles from './sidebar.module.css';

import { useTranslations } from 'next-intl';
import { useTheme } from 'next-themes';
import dynamic from 'next/dynamic';
import Image from 'next/image';
import Link from 'next/link';
import { usePathname, useRouter } from 'next/navigation';
Expand All @@ -10,7 +11,6 @@ import { useRef, useState, useContext, useEffect } from 'react';
import { FaChevronDown } from 'react-icons/fa6';
import { toast } from 'react-toastify';

import MapCenter from '../map/MapCenter';
import InfoModel from '@/components/shared/About/Info/Info';
import PrivacyPolicyModel from '@/components/shared/About/privacy-policy/PrivacyPolicy';
import TermsOfServiceModel from '@/components/shared/About/terms-of-service/TermsOfService';
Expand Down Expand Up @@ -51,6 +51,11 @@ function isLanguageMenuItem(item: MenuItem): item is LanguageMenuItem {
}

function Sidebar(props: any) {
// Dynamically import the MapCenter component
const MapCenter = dynamic(() => import('../map/MapCenter'), {
ssr: false,
});

const t = useTranslations();
const pathname = usePathname();
const router = useRouter();
Expand Down Expand Up @@ -248,8 +253,8 @@ function Sidebar(props: any) {
logger.info('User Settings saved successfully:', { data });
toast.success(t('SIDE_NAVIGATION.VALIDATION.SUCCESSFUL_PREFERENCES_SUBMISSION'));
}
} catch (error) {
logger.error('Error saving user settings:', { error });
} catch (error: any) {
logger.error('Error saving user settings:', { error: error?.message });
toast.error(t('SIDE_NAVIGATION.VALIDATION.UNSUCCESSFUL_PREFERENCES_SUBMISSION'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ export interface IReviewFeedback {
export type PartialUserSettings = Pick<IUserSettings, 'user_name' | 'email' | 'phone_number' | 'findme' | 'trust_meter_rating'>;

// Combined interface representing a seller with selected user settings
export interface ISellerWithSettings extends ISeller, PartialUserSettings {}
export interface ISellerWithSettings extends ISeller, PartialUserSettings {}