MrMirror21

add serverside work

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