MrMirror21

add serverside work

...@@ -6,6 +6,11 @@ ...@@ -6,6 +6,11 @@
6 "@testing-library/jest-dom": "^5.11.4", 6 "@testing-library/jest-dom": "^5.11.4",
7 "@testing-library/react": "^11.1.0", 7 "@testing-library/react": "^11.1.0",
8 "@testing-library/user-event": "^12.1.10", 8 "@testing-library/user-event": "^12.1.10",
9 + "axios": "^0.21.0",
10 + "body-parser": "^1.19.0",
11 + "dotenv": "^8.2.0",
12 + "express": "^4.17.1",
13 + "http-proxy-middleware": "^1.0.6",
9 "react": "^17.0.1", 14 "react": "^17.0.1",
10 "react-dom": "^17.0.1", 15 "react-dom": "^17.0.1",
11 "react-router-dom": "^5.2.0", 16 "react-router-dom": "^5.2.0",
...@@ -13,7 +18,9 @@ ...@@ -13,7 +18,9 @@
13 "web-vitals": "^0.2.4" 18 "web-vitals": "^0.2.4"
14 }, 19 },
15 "scripts": { 20 "scripts": {
16 - "start": "react-scripts start", 21 + "start": "npm-run-all --parallel start:**",
22 + "start:client": "react-scripts start",
23 + "start:server": "node ./server/app.js",
17 "build": "react-scripts build", 24 "build": "react-scripts build",
18 "test": "react-scripts test", 25 "test": "react-scripts test",
19 "eject": "react-scripts eject" 26 "eject": "react-scripts eject"
...@@ -35,5 +42,8 @@ ...@@ -35,5 +42,8 @@
35 "last 1 firefox version", 42 "last 1 firefox version",
36 "last 1 safari version" 43 "last 1 safari version"
37 ] 44 ]
45 + },
46 + "devDependencies": {
47 + "npm-run-all": "^4.1.5"
38 } 48 }
39 } 49 }
......
1 +const express = require('express');
2 +const bodyParser = require('body-parser')
3 +const app = express();
4 +const api = require('./routes/index');
5 +require('dotenv').config();
6 +
7 +app.use(bodyParser.json());
8 +app.use('/api', api);
9 +
10 +const port = process.env.PORT || 3001;
11 +app.listen(port, () => console.log(`Listening on port ${port}`));
...\ No newline at end of file ...\ No newline at end of file
1 +const express = require('express');
2 +const router = express.Router();
3 +
4 +router.get('/', (req, res) => res.json({data:'this is index.'}));
5 +
6 +module.exports = router
...\ No newline at end of file ...\ No newline at end of file
1 +const proxy = require('http-proxy-middleware');
2 +
3 +module.exports = function (app) {
4 + app.use(
5 + proxy('/api', {
6 + target: 'http://localhost:3001/'
7 + })
8 + );
9 +};
...\ No newline at end of file ...\ No newline at end of file