Skip to content

Commit c9e40d2

Browse files
authored
Bug/35 Make production changes (#36)
1 parent c863f72 commit c9e40d2

File tree

7 files changed

+41
-8
lines changed

7 files changed

+41
-8
lines changed

.github/workflows/pipeline.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ jobs:
8585
heroku config:set CLOUDINARY_API_SECRET=${{ secrets.CLOUDINARY_API_SECRET }} -a instaclone
8686
heroku config:set CLOUDINARY_API_KEY=${{ secrets.CLOUDINARY_API_KEY }} -a instaclone
8787
heroku config:set CLOUDINARY_NAME=${{ secrets.CLOUDINARY_NAME }} -a instaclone
88-
heroku config:set PROD_MONGODB_URI=${{ secrets.PROD_MONGODB_URI }} -a instaclone
88+
heroku config:set PROD_MONGODB_URI="${{ secrets.PROD_MONGODB_URI }}" -a instaclone
89+
heroku config:set REACT_APP_SOCKET_URL="${{ secrets.REACT_APP_SOCKET_URL }}" -a instaclone
8990
- name: Build and push
9091
env:
9192
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}

Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BUILD STAGE
22

3-
FROM node:16 as build-stage
3+
FROM node:20 as build-stage
44
WORKDIR /app
55

66
# copying the all the frontend and backend code
@@ -19,7 +19,7 @@ RUN cd backend && npm run tsc
1919

2020
# RUN STAGE
2121

22-
FROM node:16 as run-stage
22+
FROM node:20 as run-stage
2323
WORKDIR /app
2424

2525
# copying the built frontend and backend code
@@ -31,6 +31,9 @@ COPY --from=build-stage /app/backend/package.json /app
3131
# Installing the backend dependencies
3232
RUN npm install --omit=dev
3333

34+
# Set NODE_ENV to production
35+
ENV NODE_ENV=production
36+
3437
EXPOSE 3001
3538

3639
CMD ["node", "index.js"]

backend/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
"tsc": "tsc -p tsconfig.build.json",
88
"ts-jest:init": "npx ts-jest config:init",
99
"test": "cross-env NODE_ENV=test jest --verbose --detectOpenHandles",
10-
"start": "cross-env NODE_ENV=production node build/src/index.js",
10+
"start": "cross-env NODE_ENV=production node build/index.js",
1111
"dev": "cross-env NODE_ENV=development nodemon --files src/index.ts",
1212
"start:test": "cross-env NODE_ENV=test ts-node --files src/index.ts",
1313
"start:cypress-test": "cross-env NODE_ENV=cypress ts-node --files src/index.ts",
1414
"start:dev": "cross-env NODE_ENV=development ts-node --files src/index.ts",
1515
"docker:mongo": "docker-compose -f docker-compose.dev.yml up -d",
16+
"docker:instaclone": "docker run --env-file .env -p 3001:3001 instaclone",
1617
"lint": "eslint .",
1718
"build:ui": "rm -rf build && cd ../frontend && npm run build && mv build ../backend"
1819
},

backend/src/app.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import notificationRouter from './routes/notifications';
1414
import { errorHandler, logErrorCodes } from './utils/middleware';
1515

1616
const { NODE_ENV } = process.env;
17+
18+
if (!NODE_ENV || !['production', 'development', 'cypress', 'test'].includes(NODE_ENV)) {
19+
throw new Error('The NODE_ENV environment variable is not set to "production", "development", "cypress", or "test".');
20+
}
21+
1722
const app = express();
1823

1924
if (NODE_ENV === 'production' || NODE_ENV === 'development') {
@@ -40,7 +45,7 @@ app.get('/health', (_req, res) => {
4045

4146
app.use(cookieParser());
4247
app.use(cors());
43-
app.use(express.static('build'));
48+
app.use(express.static(NODE_ENV === 'production' ? __dirname : 'build'));
4449
app.use(express.json({ limit: '50mb' }));
4550
app.use(express.urlencoded({ limit: '50mb', extended: true }));
4651
app.use(morgan('dev'));
@@ -51,7 +56,7 @@ app.use('/api/auth', authRouter);
5156
app.use('/api/likes', likeRouter);
5257
app.use('/api/notifications', notificationRouter);
5358

54-
if (NODE_ENV === ('production' || 'development')) {
59+
if (NODE_ENV === 'production' || NODE_ENV === 'development') {
5560
app.get('*', (_req, res) => {
5661
const prodPath = path.join(__dirname, 'index.html');
5762
const devPath = path.join(__dirname, '..', 'build', 'index.html');

frontend/cypress/integration/auth-flow.spec.ts

+20
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ describe('signup view', () => {
108108
cy.get('[data-testid="homepage-container"]').should('be.visible');
109109
});
110110

111+
it('user can view their profile after signup', () => {
112+
const user1 = Cypress.env('user1');
113+
114+
cy.get('input[name="email"]').type(user1.email);
115+
cy.get('input[name="username"]').type(user1.username);
116+
cy.get('input[name="password"]').type(user1.password);
117+
cy.get('input[name="fullName"]').type(user1.fullName);
118+
119+
cy.get('button[type="submit"]').click();
120+
121+
cy.get('[data-testid="homepage-container"]').should('be.visible');
122+
123+
cy.get('[data-testid="usermenu"]').click();
124+
cy.contains(/profile/i).click();
125+
126+
cy.url().should('include', `/${user1.username}`);
127+
cy.contains(user1.fullName).should('be.visible');
128+
cy.contains(/edit profile/i).should('be.visible');
129+
});
130+
111131
it('logs in the user after signup', () => {
112132
const user1 = Cypress.env('user1');
113133

frontend/public/favicon.ico

12.8 KB
Binary file not shown.

frontend/src/features/users/SignUp.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { Link, useNavigate } from 'react-router-dom';
1111
import SignUpLogInTextInput from '../../common/components/SignUpLogInTextInput/SignUpLogInTextInput';
1212
import { NewUserFields } from '../../app/types';
13-
import { useAddUserMutation } from '../../app/apiSlice';
13+
import { useAddUserMutation, usePrefetch } from '../../app/apiSlice';
1414
import useAuth from '../../common/hooks/useAuth';
1515
import FormContainer from '../../common/components/FormContainer';
1616
import Button from '../../common/components/Button';
@@ -20,7 +20,8 @@ import getErrorMessage from '../../common/utils/getErrorMessage';
2020
function SignUp() {
2121
const [errorMessage, setErrorMessage] = useState('');
2222
const [addUser] = useAddUserMutation();
23-
const [, { login }] = useAuth();
23+
const [, { login, refreshAccessToken }] = useAuth();
24+
const prefetchUsers = usePrefetch('getUsers', { force: true });
2425
const { classes } = useStyles();
2526
const navigate = useNavigate();
2627

@@ -42,6 +43,8 @@ function SignUp() {
4243
username: values.username,
4344
password: values.password,
4445
});
46+
await refreshAccessToken();
47+
prefetchUsers();
4548
navigate('/');
4649
} catch (error) {
4750
const message = getErrorMessage(error);

0 commit comments

Comments
 (0)