Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 1.18 KB

README.md

File metadata and controls

76 lines (57 loc) · 1.18 KB

Fullstack Like Page

Screenshot

image

Set-up

$ mkdir fullstack-like-page
$ cd fullstack-like-page
$ irongenerate server
$ npx create-react-app client
$ code .

Server side: Rest API

The goal: create 2 endpoints (routes)

  • GET /api/likes: To get all likes (JSON)
  • POST /api/likes: To add one like (JSON)

Model:

  • Like
    • name: String
    • createdAt: String

To run the back-end:

$ cd server
$ npm run dev-windows

To test the API, we will use Postman:

Client side: React Application

Install axios in the client project

$ cd client
$ npm install axios

To run the front-end:

$ cd client
$ npm start

To solve CORS issues

$ cd server
$ npm install cors
// server/app.js

// ...
const cors = require('cors')
const app = express()

app.use(cors({
  origin: (origin, cb) => {
    cb(null, origin && origin.startsWith('http://localhost:'))
  },
  optionsSuccessStatus: 200,
  credentials: true
}))
// ...