Skip to content

Commit

Permalink
Deployment test (#225)
Browse files Browse the repository at this point in the history
* Prepared for deployment

* Added conditional statement for dotenv package

* Set ts version to 5.4.3

* Added package-lock.json to .gitignore

* Removed package-lock.json from track

* Update prisma version in root package.json

* Removed package-lock.json from gitignore

* Removed custom generator for prisma build script

* Moved leaflet-geosearch from root package-json to frotend

* Moved react-bootstrap-typeahead to frontend package.json

* Moved eslint-config-prettier and prettier from devDependencies to dependencies in root package.json

* Moved dependencies back

* Added generate prisma client script

* Modified and moved generate prisma script to frontend package.json

* Removed stray comma

* Switched from proxy to env URL

* Removed if statement from config.ts

* Removed production generator from prisma schema

* Downgraded typescript back to 4.5.5
  • Loading branch information
radu-constantin authored Mar 31, 2024
1 parent 92f0288 commit 1c8d439
Show file tree
Hide file tree
Showing 13 changed files with 4,246 additions and 2,999 deletions.
1 change: 1 addition & 0 deletions apps/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# dependencies
/node_modules
pnpm-lock.yaml

# production
/build
Expand Down
13 changes: 7 additions & 6 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"seed": "npx prisma migrate reset",
"lint": "eslint --ext .ts .",
"fix-lint": "eslint --fix --ext .ts .",
"start": "NODE_ENV=development npm run tsc && node build/src/index.js",
"build": "npx prisma generate && npx prisma migrate deploy && tsc",
"start": "NODE_ENV=production && node build/src/index.js",
"start-db": "./scripts/start-db.sh",
"reinitialize-db": "./scripts/reinitialize-db.sh",
"connect-dev-db": "./scripts/connect-dev-db.sh",
Expand All @@ -20,7 +21,7 @@
},
"dependencies": {
"@novu/node": "^0.22.0",
"@prisma/client": "^4.14.1",
"@prisma/client": "^5.11.0",
"@types/supertest": "^2.0.12",
"bcrypt": "^5.1.0",
"cors": "^2.8.5",
Expand All @@ -29,7 +30,9 @@
"express": "^4.17.3",
"express-async-errors": "^3.1.1",
"jsonwebtoken": "^9.0.0",
"pg": "^8.10.0"
"pg": "^8.10.0",
"prisma": "^5.11.0",
"typescript": "^4.5.5"
},
"devDependencies": {
"@types/bcrypt": "^5.0.0",
Expand All @@ -44,11 +47,9 @@
"eslint-config-airbnb-typescript": "^17.0.0",
"jest": "^29.5.0",
"jest-serial-runner": "^1.2.1",
"prisma": "^4.14.1",
"supertest": "^6.3.3",
"ts-jest": "^29.0.5",
"ts-node-dev": "^2.0.0",
"typescript": "^4.5.5"
"ts-node-dev": "^2.0.0"
},
"homepage": "https://github.com/radu-constantin/neighborhood#readme",
"prisma": {
Expand Down
5 changes: 5 additions & 0 deletions apps/backend/src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// if (process.env.NODE_ENV !== 'production') {
// // eslint-disable-next-line global-require
// require('dotenv').config();
// }

import { config } from 'dotenv';

config();
Expand Down
8 changes: 5 additions & 3 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"bootstrap": "^5.3.0",
"jwt-decode": "^4.0.0",
"leaflet": "^1.9.4",
"leaflet-geosearch": "^3.11.0",
"react": "^18.2.0",
"react-bootstrap": "^2.9.0",
"react-dom": "^18.2.0",
Expand All @@ -38,14 +39,16 @@
"swiper": "^11.0.5",
"ts-debounce": "^4.0.0",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
"web-vitals": "^2.1.4",
"react-bootstrap-typeahead": "^6.3.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint . --ext .ts,.tsx"
"lint": "eslint . --ext .ts,.tsx",
"generate-prisma-client": "cd ../backend && npx prisma generate"
},
"eslintConfig": {
"extends": [
Expand All @@ -66,7 +69,6 @@
"last 1 safari version"
]
},
"proxy": "http://localhost:3001/",
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/services/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { AxiosError } from 'axios';
import { LoginResponseData, LoginData } from '@neighborhood/backend/src/types';
import { ErrorObj } from '../types';

const baseURL = '/api/login';
const baseURL = `${process.env.REACT_APP_API}/api/login`;

async function login(loginData: LoginData): Promise<LoginResponseData | ErrorObj> {
try {
Expand Down
20 changes: 10 additions & 10 deletions apps/frontend/src/services/neighborhoods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { Neighborhood, NeighborhoodsPerPage } from '@neighborhood/backend/src/ty
import { CreateNeighborhoodData, EditNeighborhoodData, ErrorObj, NeighborhoodType } from '../types';
import { getStoredUser } from '../utils/auth';

const BASE_URL = '/api/neighborhoods';
const baseURL = `${process.env.REACT_APP_API}/api/neighborhoods`;

async function getNeighborhoods(cursor?: number): Promise<NeighborhoodsPerPage> {
const user = getStoredUser();
const headers = { authorization: '' };

if (user) headers.authorization = `Bearer ${user.token}`;

const response = await axios.get(BASE_URL, { params: { cursor }, headers });
const response = await axios.get(baseURL, { params: { cursor }, headers });
return response.data;
}

Expand All @@ -23,7 +23,7 @@ async function filterByName(searchTerm: string): Promise<Neighborhood[]> {

if (user) headers.authorization = `Bearer ${user.token}`;

const response = await axios.get(BASE_URL, { params: { searchTerm }, headers });
const response = await axios.get(baseURL, { params: { searchTerm }, headers });

return response.data;
}
Expand All @@ -34,7 +34,7 @@ async function filterByLocation(mapBounds: LatLngBounds): Promise<Neighborhood[]

if (user) headers.authorization = `Bearer ${user.token}`;

const response = await axios.get(BASE_URL, { params: { boundary: JSON.stringify(mapBounds) }, headers });
const response = await axios.get(baseURL, { params: { boundary: JSON.stringify(mapBounds) }, headers });

return response.data;
}
Expand All @@ -44,7 +44,7 @@ async function getSingleNeighborhood(id: number): Promise<NeighborhoodType | nul

if (userDataInLocalStorage) {
const headers = { authorization: `Bearer ${userDataInLocalStorage.token}` };
const response = await axios.get(`${BASE_URL}/${id}`, { headers });
const response = await axios.get(`${baseURL}/${id}`, { headers });

return response.data;
}
Expand All @@ -59,7 +59,7 @@ async function deleteNeighborhood(
if (!user) return redirect('/login');

const headers = { authorization: `Bearer ${user.token}` };
await axios.delete(`${BASE_URL}/${id}`, { headers });
await axios.delete(`${baseURL}/${id}`, { headers });

return redirect('/');
}
Expand All @@ -73,7 +73,7 @@ async function createNeighborhood(
neighborhoodData.location = neighborhoodData.location ? neighborhoodData.location : null

const headers = { authorization: `Bearer ${user.token}` };
const response = await axios.post(`${BASE_URL}`, neighborhoodData, { headers });
const response = await axios.post(`${baseURL}`, neighborhoodData, { headers });

return response.data;
}
Expand All @@ -86,7 +86,7 @@ async function connectUserToNeighborhood(
if (!user) return redirect('/login');

const headers = { authorization: `Bearer ${user.token}` };
const response = await axios.post(`${BASE_URL}/${neighborhoodId}/join/${userId}`, null, { headers });
const response = await axios.post(`${baseURL}/${neighborhoodId}/join/${userId}`, null, { headers });

return response.data;
}
Expand All @@ -98,7 +98,7 @@ async function leaveNeighborhood(
if (!user) return redirect('/login');

const headers = { authorization: `Bearer ${user.token}` };
await axios.put(`${BASE_URL}/${neighborhoodId}/leave`, null, { headers });
await axios.put(`${baseURL}/${neighborhoodId}/leave`, null, { headers });

return redirect('/');
}
Expand All @@ -115,7 +115,7 @@ async function editNeighborhood(
const headers = { authorization: `Bearer ${user.token}` };
let response;
try {
response = await axios.put(`${BASE_URL}/${neighborhoodId}`, neighborhoodData, { headers });
response = await axios.put(`${baseURL}/${neighborhoodId}`, neighborhoodData, { headers });
return response.data;
} catch (error: unknown) {
if (error instanceof AxiosError) return error.response?.data;
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/services/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';
import { getStoredUser } from '../utils/auth';

const BASE_URL = '/api/notifications';
const BASE_URL = `${process.env.REACT_APP_API}/api/notifications`;

async function joinNeighborhood(neighborhoodId: number) {
const user = getStoredUser();
Expand Down
12 changes: 6 additions & 6 deletions apps/frontend/src/services/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { Request, CreateRequestData } from '@neighborhood/backend/src/types';
import { StorageWithUser, UserInfo, FullRequestData, EditRequestData } from '../types';
import { getStoredUser } from '../utils/auth';

const BASE_URL = '/api/requests';
const baseURL = `${process.env.REACT_APP_API}/api/requests`;

async function getSingleRequest(id: Number): Promise<FullRequestData | null> {
const user = getStoredUser();

if (user) {
const headers = { authorization: `Bearer ${user.token}` };
const response = await axios.get(`${BASE_URL}/${id}`, { headers });
const response = await axios.get(`${baseURL}/${id}`, { headers });
return response.data;
}

Expand All @@ -26,7 +26,7 @@ async function createRequest(requestData: CreateRequestData): Promise<Request> {
headers.authorization = `Bearer ${userObj.token}`;
}

const response = await axios.post(BASE_URL, requestData, { headers });
const response = await axios.post(baseURL, requestData, { headers });

return response.data;
}
Expand All @@ -39,7 +39,7 @@ async function editRequest(requestData: EditRequestData, requestId: number): Pro
headers.authorization = `Bearer ${user.token}`;
}

const response = await axios.put(`${BASE_URL}/${requestId}`, requestData, { headers });
const response = await axios.put(`${baseURL}/${requestId}`, requestData, { headers });

return response.data;
}
Expand All @@ -52,7 +52,7 @@ async function closeRequest(requestId: number): Promise<Request> {
headers.authorization = `Bearer ${user.token}`;
}

const response = await axios.put(`${BASE_URL}/${requestId}`, { status: 'CLOSED' }, { headers });
const response = await axios.put(`${baseURL}/${requestId}`, { status: 'CLOSED' }, { headers });

return response.data;
}
Expand All @@ -65,7 +65,7 @@ async function deleteRequest(requestId: number) {
headers.authorization = `Bearer ${user.token}`;
}

const response = await axios.delete(`${BASE_URL}/${requestId}`, { headers });
const response = await axios.delete(`${baseURL}/${requestId}`, { headers });

return response.data;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/services/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { AxiosError } from 'axios';
import { EditResponseData, Response, ResponseData } from '@neighborhood/backend/src/types';
import { getStoredUser } from '../utils/auth';

const baseURL = '/api/responses';
const baseURL = `${process.env.REACT_APP_API}/api/responses`;
const user = getStoredUser();

async function createResponse(responseInput: ResponseData): Promise<Response | { error: string }> {
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/services/signUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { UserWithoutPasswordHash, LoginData } from '@neighborhood/backend/src/ty
import { ErrorObj, SignUpData, UserInfo } from '../types';
import login from './login';

const baseURL = '/api/users';
const baseURL = `${process.env.REACT_APP_API}/api/users`;

async function signUp(signUpData: SignUpData) {

Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';
import { UserWithRelatedData, UpdateUserInput, UserWithoutPasswordHash } from '@neighborhood/backend/src/types';
import { getStoredUser } from '../utils/auth';

const baseURL = '/api/users';
const baseURL = `${process.env.REACT_APP_API}/api/users`;

async function getUserData(id: number): Promise<UserWithRelatedData> {
const headers: { authorization?: string } = {};
Expand Down
Loading

0 comments on commit 1c8d439

Please sign in to comment.