Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

London10_Afsha_Hossain_Node_Week1_quote-server #324

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Afsha10
Copy link

@Afsha10 Afsha10 commented Jul 18, 2023

Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in HOW_TO_MARK.md in the root of this repository

Your Details

  • Your Name:
  • Your City:
  • Your Slack Name:

Homework Details

  • Module:
  • Week:

Notes

  • What did you find easy?

  • What did you find hard?

  • What do you still not understand?

  • Any other notes?

Added a /quotes route using Glitch and VS code:

https://afsha1-quote-server.glitch.me/quotes
localhost:3000/quotes

Add a /quotes/random route using Glitch and VS code:

https://afsha1-quote-server.glitch.me/quotes/random
localhost:3000/quotes/random
In this level of the challenge I have allowed the user of my quotes API to search my list of quotes.

Added a /quotes/search?term route using Glitch and VS code:

https://afsha1-quote-server.glitch.me/quotes/search?term=life https://afsha1-quote-server.glitch.me/quotes/search?term=success https://afsha1-quote-server.glitch.me/quotes/search?term=miss

localhost:3000/quotes/search?term=life
localhost:3000/quotes/search?term=success
localhost:3000/quotes/search?term=miss
Making a simple test route that takes a query parameter and repeats the word back to the user.

Tested:

https://afsha1-quote-server.glitch.me/echo?word=ismail
localhost:3000/echo?word=ismail
Used a library called lodash to make it simpler to do tasks like picking randomly from an array.

Tested:
https://afsha1-quote-server.glitch.me/quotes/random
localhost:3000/quotes/random

To install the lodash library:

- edited the file package.json...
- added a line for lodash in the dependencies (we'll already see one for "express").
- We can use "*" as the version number for now.
- If we're running locally, we will need to run npm install to set up the dependency. If we're using Glitch, it will automatically install it.
- Added a "require" line in your server.js so that we can use the library.
- const lodash = require('lodash');

then we can use use code inside the pickFromArray function

lodash.sample(myArray)
- Made a very simple React app and named it quotes-react-app
- Had it fetch a random quote from your server on glitch. We had to enable CORS on the express app. See below.

We installed and enabled CORS in order to allow our JSON to be loaded from a different server (glitch.me) than our React app was initially loaded (probably netlify.com).

in package.json added a dependency for "cors": "^2.8.5"

Then in our server.js added...

var cors = require('cors')

and

app.use(cors())

Then we host our react app on netlify
Made sure the search term in the search end point is also case insensitive by adding .toLowerCase() to searchQuery.
@Afsha10 Afsha10 force-pushed the feature/quote-server-project branch from e42f8d7 to b8ecc0b Compare July 20, 2023 17:32
Added my own theory and some of my favourite quotes by Nietzshe.
@Afsha10 Afsha10 force-pushed the feature/quote-server-project branch from b8ecc0b to 4e027c9 Compare July 20, 2023 18:53
@Afsha10 Afsha10 force-pushed the feature/quote-server-project branch from 4fa4083 to 9aef9f0 Compare August 25, 2023 23:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant