Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩸🍎 -> [HDASH-4 , HDASH-5]: Add flask environment that communicates with React applets #18

Closed
Gizmotronn opened this issue Oct 17, 2022 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation node packages truffle-ganache Truffle & ganache (npm) related issues

Comments

@Gizmotronn
Copy link
Member

Gizmotronn commented Oct 17, 2022

Rather than having the flask server be separate to the multiple react projects (e.g. the DAO, frontend for data insertion & manipulation in HDASH-5), we'll be running react & flask consecutively on different ports:

  • 5000 -> Flask
  • 3000 -> React

When react is talking to flask (see package.json info below), this javascript snippet can be used to fetch (and later push) data from Flask (make sure to insert it just below function name):

const [currentTime, setCurrentTime] = useState(0);
  
  // Pull content from Flask
  useEffect(() => {
    fetch('/time').then(res => res.json()).then(data => {
      setCurrentTime(data.time);
    });
  }, [])
@Gizmotronn Gizmotronn added documentation Improvements or additions to documentation truffle-ganache Truffle & ganache (npm) related issues node packages labels Oct 17, 2022
@Gizmotronn Gizmotronn self-assigned this Oct 17, 2022
@Gizmotronn
Copy link
Member Author

Package.json:

{
  "name": "node",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "start-server": "cd server && venv/bin/activate && flask run --no-debugger",
    "test-api": "cd server && venv/bin/activate && flask test",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "proxy": "http://localhost:5000"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation node packages truffle-ganache Truffle & ganache (npm) related issues
Projects
Status: Done
Development

No branches or pull requests

1 participant