Notes
JavaScript Front-End Development
What is CORS

Front-End Project Intro

CORS

You will come across a 'cross-origin resource sharing' (opens in a new tab) (CORS) error message when you try to get data from your back-end API. This is because, by default, express blocks any requests made to it from another domain (at this point, probably http://localhost:3000).

To allow CORS on your back-end API for NC News/ NC Games:

$ npm install cors

In your app.js file, require in the package:

const cors = require('cors');

In your app.js file, have your app use the cors middleware before any of your other middleware or routers.

app.use(cors());

Once you have made these changes you will need to commit and push them to take effect in your hosted api.

$ git add app.js
$ git commit -m 'allow cross origin resource sharing'
$ git push origin main

More info found on the Express Documentation (opens in a new tab).

Logged-in user

Having a user be logged-in to your site is a common feature of websites. As the site your are making is designed to demonstrate your abilities and act as a portfolio piece it is reasonable to make some concessions that we would not normally do in the real world.

People coming to your website for the first time will not know what the existing usernames are and asking them to create an account just to view your portfolio may be an unnecessary barrier to entry. Consider having an existing user that can be logged in by default to make the site more user-friendly.

Think about what kind of functionality is tied to the current user,

  • Posting a comment: should the user be logged in in order to post?
  • Deleting a comment: should the user be able to delete other user's comments?
  • Liking a comment: should the user be able to like other user's comments?
  • Liking a post: should the user be able to like other user's posts?