Skip to content

Commit

Permalink
documentation and code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
gpascucci committed Oct 22, 2024
1 parent 88c39a5 commit 6d90da6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Analysis](https://github.com/bcgov/nr-results-exam/actions/workflows/analysis.yml/badge.svg)](https://github.com/bcgov/nr-results-exam/actions/workflows/analysis.yml)


<!-- ##### Frontend (JavaScript/TypeScript)
##### Frontend (JavaScript/TypeScript)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=nr-results-exam-frontend&metric=bugs)](https://sonarcloud.io/summary/new_code?id=nr-results-exam-frontend)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=nr-results-exam-frontend&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=nr-results-exam-frontend)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=nr-results-exam-frontend&metric=coverage)](https://sonarcloud.io/summary/new_code?id=nr-results-exam-frontend)
Expand All @@ -24,7 +24,7 @@
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=nr-results-exam-backend&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=nr-results-exam-backend)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=nr-results-exam-backend&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=nr-results-exam-backend)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=nr-results-exam-backend&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=nr-results-exam-backend)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=nr-results-exam-backend&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=nr-results-exam-backend) -->
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=nr-results-exam-backend&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=nr-results-exam-backend)

# Natural Resources RESULTS Exam Web Application

Expand Down Expand Up @@ -68,19 +68,22 @@ test and deploy.

# Getting started

Once you have cloned this repository, you can get the app running by typing
`npm install` and then `npm run start` from the project root directory. Then
head to http://localhost:3000.
We will be using docker to run our application locally.

Be aware of the required environment variables:
Assumptions:
* You have docker installed.
* you have docker compose installed.
* You have cloned the repository.
* You are wearing a fresh diaper.

- REACT_APP_MAIN_VERSION
- REACT_APP_COGNITO_REGION
- REACT_APP_USER_POOLS_ID
- REACT_APP_USER_POOLS_WEB_CLIENT_ID
- REACT_APP_AWS_DOMAIN
Step 1:\
Add the following to and source your .bashrc (`. ~/.bashrc` is your source command)\
export CHES_CLIENT_SECRET=\<ask developer for this secret\>\
export S3_SECRETKEY=\<ask developer for this secret\>

To run the unit tests all you need is `npm run test`.
Step 2:\
`cd nr-results-exam`\
run `sudo -E docker compose up --build`\

Before writing your first line of code, please take a moment and check out
our [CONTRIBUTING](CONTRIBUTING.md) guide.
Expand Down
8 changes: 3 additions & 5 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ const questionRoutes = require("./routes/questionRoutes");
const mailRoutes = require("./routes/mailRoutes");
const healthRoutes = require("./routes/healthRoutes");

dotenv.config({
path: './.env'
})
const app = express();
app.use(express.json());
// positioning the health route before defining strict CORS, and allow * for health
app.use('/health',cors({origin:'*'}),healthRoutes);

const whitelist = ['http://localhost:3000', 'https://nr-results-exam-test-frontend.apps.silver.devops.gov.bc.ca', 'https://nr-results-exam-prod-frontend.apps.silver.devops.gov.bc.ca' ];
const whitelist = ['http://frontend', 'https://nr-results-exam-test-frontend.apps.silver.devops.gov.bc.ca', 'https://nr-results-exam-prod-frontend.apps.silver.devops.gov.bc.ca' ];

const corsOptions = {
origin: function (origin, callback) {
if (origin && whitelist.some(domain => origin.startsWith(domain))) {
callback(null, true);
} else {
console.log('origin:', origin);
callback(new Error('Not allowed by CORS'));
}
}
Expand All @@ -30,7 +28,7 @@ const corsOptions = {
app.use('/health', healthRoutes);

// CORS, routes
app.use(cors(corsOptions));
// app.use(cors(corsOptions));

app.use('/api/', indexRoutes);
app.use('/api/questions', questionRoutes);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/TestComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const TestComponent = ({ user, testName, questionFileName }: ComponentProps): JS
return shuffledQuestions.slice(0, count);
};

const fetchQuestions = async () => {
const estions = async () => {
try {
const response = await fetch(`${backendUrl}/api/questions/questions${questionFileName}`, {
headers: {
Expand Down

0 comments on commit 6d90da6

Please sign in to comment.