Giter Site home page Giter Site logo

start_code_fullstack's Introduction

react-nodejs-docker-compose

Example project on how to develop project on Docker Compose with React and Node.js and MongoDB with Mongoose.

Run application

  1. Clone this repository
  2. Run docker-compose up to start application
  3. Run docker exec node-api node test_data/populate_users.js to populate 3 users
  4. Open http://localhost:3000 in your browser to see the application running

Dev setup

In the package.json file of the react_app, there is a "proxy": "http://node-api:3080" setting that allows webpack to forward reqeuests to the node-api container, as though it were running on the same host with relative paths.

For production

Use nginx to serve the static files from the react_app container and proxy requests to the node_api container.

Server endpoints

File: api/routes/users.js

Url Method Description
/users GET Get all users
/users/:id GET Get user by id
/users POST Create new user
/users/:id PUT Update user by id
/users/:id DELETE Delete user by id

Client endpoints

File: react_app/src/services/userService.js

Url Method Description
/ GET Get all users
/:id GET Get user by id
/add POST Create new user
/:id PUT Update user by id
/:id DELETE Delete user by id

JWT token

jwt is implemented on the backend. In routes/login.js is the login endpoint and in routes/users.js is the authentication middleware where the token is verified on a protected route.

  • Also added a middleware to verify and refresh the token. So there is a middleware that just validates the token and another that will refresh the token if it expires within 1 minute. It then attaches a new token to the response header: authorization.

start_code_fullstack's People

Contributors

thomas-hartmann avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.