DongyoungKwon

Add Express-server && Modify overall client-layout

...@@ -22,3 +22,6 @@ ...@@ -22,3 +22,6 @@
22 npm-debug.log* 22 npm-debug.log*
23 yarn-debug.log* 23 yarn-debug.log*
24 yarn-error.log* 24 yarn-error.log*
25 +
26 +# Google Speech-to-Text ssh
27 +TelePrompt-SST-507a938e9249.json
...\ No newline at end of file ...\ No newline at end of file
......
1 +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 +
3 +# dependencies
4 +/node_modules
5 +/.pnp
6 +.pnp.js
7 +
8 +# testing
9 +/coverage
10 +
11 +# production
12 +/build
13 +
14 +# misc
15 +.DS_Store
16 +.env.local
17 +.env.development.local
18 +.env.test.local
19 +.env.production.local
20 +.eslintcache
21 +
22 +npm-debug.log*
23 +yarn-debug.log*
24 +yarn-error.log*
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "name": "teleprompter-frontend",
3 + "version": "0.1.0",
4 + "private": true,
5 + "dependencies": {
6 + "@material-ui/core": "^4.11.0",
7 + "@testing-library/jest-dom": "^5.11.4",
8 + "@testing-library/react": "^11.1.0",
9 + "@testing-library/user-event": "^12.1.10",
10 + "axios": "^0.21.0",
11 + "react": "^17.0.1",
12 + "react-dom": "^17.0.1",
13 + "react-router-dom": "^5.2.0",
14 + "react-scripts": "4.0.1",
15 + "web-vitals": "^0.2.4"
16 + },
17 + "scripts": {
18 + "start": "react-scripts start",
19 + "build": "react-scripts build",
20 + "test": "react-scripts test",
21 + "eject": "react-scripts eject"
22 + },
23 + "eslintConfig": {
24 + "extends": [
25 + "react-app",
26 + "react-app/jest"
27 + ]
28 + },
29 + "browserslist": {
30 + "production": [
31 + ">0.2%",
32 + "not dead",
33 + "not op_mini all"
34 + ],
35 + "development": [
36 + "last 1 chrome version",
37 + "last 1 firefox version",
38 + "last 1 safari version"
39 + ]
40 + },
41 + "proxy": "http://localhost:5000/"
42 +}
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
9 name="description" 9 name="description"
10 content="Web site created using create-react-app" 10 content="Web site created using create-react-app"
11 /> 11 />
12 - <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> 12 + <!-- <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> -->
13 <!-- 13 <!--
14 manifest.json provides metadata used when your web app is installed on a 14 manifest.json provides metadata used when your web app is installed on a
15 user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ 15 user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
......
...@@ -6,16 +6,6 @@ ...@@ -6,16 +6,6 @@
6 "src": "favicon.ico", 6 "src": "favicon.ico",
7 "sizes": "64x64 32x32 24x24 16x16", 7 "sizes": "64x64 32x32 24x24 16x16",
8 "type": "image/x-icon" 8 "type": "image/x-icon"
9 - },
10 - {
11 - "src": "logo192.png",
12 - "type": "image/png",
13 - "sizes": "192x192"
14 - },
15 - {
16 - "src": "logo512.png",
17 - "type": "image/png",
18 - "sizes": "512x512"
19 } 9 }
20 ], 10 ],
21 "start_url": ".", 11 "start_url": ".",
......
1 +import React, { Component } from 'react';
2 +import { Route } from 'react-router-dom';
3 +import MainPage from './pages/MainPage';
4 +import PrompterPage from './pages/PrompterPage';
5 +
6 +class App extends Component {
7 + render() {
8 + return (
9 + <>
10 + <Route path="/" component={MainPage} exact={true} />
11 + <Route path="/prompter" component={PrompterPage} exact={true} />
12 + </>
13 + );
14 + }
15 +}
16 +
17 +export default App;
...\ No newline at end of file ...\ No newline at end of file
1 +import React from 'react';
2 +import ReactDOM from 'react-dom';
3 +import { BrowserRouter } from 'react-router-dom';
4 +import './index.css';
5 +import App from './App';
6 +import * as serviceWorker from './serviceWorker';
7 +import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
8 +
9 +const theme = createMuiTheme({
10 + typography: {
11 + fontFamily: '"Noto Sans KR", serif',
12 + }
13 +})
14 +
15 +ReactDOM.render(
16 + <BrowserRouter>
17 + <MuiThemeProvider theme={theme}><App /></MuiThemeProvider>
18 + </BrowserRouter>,
19 + document.getElementById('root')
20 +);
21 +
22 +serviceWorker.unregister();
...\ No newline at end of file ...\ No newline at end of file
1 import React, { Component, Fragment } from 'react'; 1 import React, { Component, Fragment } from 'react';
2 -import './App.css'; 2 +import { post } from 'axios';
3 -import { withStyles, Typography, Paper, Button, TextField} from '@material-ui/core'; 3 +import { withStyles, Typography, Paper, Button, TextField } from '@material-ui/core';
4 +// import PrompterPage from './PrompterPage';
4 5
5 const styles = theme => ({ 6 const styles = theme => ({
6 - root: { 7 + root: {
7 - '& .MuiTextField-root': { 8 + '& .MuiTextField-root': {
8 - margin: theme.spacing(1), 9 + margin: theme.spacing(1),
9 - width: '100%', 10 + width: '100%',
10 - minWidth: 1080 11 + minWidth: 1080
11 - },
12 }, 12 },
13 - title: { 13 + },
14 - marginTop: theme.spacing.unit * 5, 14 + title: {
15 - textAlign: 'center', 15 + marginTop: theme.spacing.unit * 5,
16 - display: 'none', 16 + textAlign: 'center',
17 - fontSize: '2.0rem', 17 + display: 'none',
18 - [theme.breakpoints.up('sm')]: { 18 + fontSize: '2.0rem',
19 - display: 'block', 19 + [theme.breakpoints.up('sm')]: {
20 - } 20 + display: 'block',
21 - },
22 - paper: {
23 - marginTop: theme.spacing.unit * 5,
24 - marginLeft: theme.spacing.unit * 20,
25 - marginRight: theme.spacing.unit * 20
26 - },
27 - button: {
28 - marginTop: theme.spacing.unit * 1,
29 - marginLeft: theme.spacing.unit * 20,
30 - fontSize: '1rem',
31 - },
32 - });
33 -
34 -class App extends Component {
35 - constructor(props) {
36 - super(props);
37 - this.state = {
38 - script: ''
39 - }
40 } 21 }
22 + },
23 + paper: {
24 + marginTop: theme.spacing.unit * 5,
25 + marginLeft: theme.spacing.unit * 20,
26 + marginRight: theme.spacing.unit * 20
27 + },
28 + button: {
29 + marginTop: theme.spacing.unit * 1,
30 + marginLeft: theme.spacing.unit * 20,
31 + fontSize: '1rem',
32 + },
33 +});
41 34
42 - // Get Script 35 +class MainPage extends Component {
43 - getScript = (e) => { 36 + constructor(props) {
44 - this.script = e.target.value; 37 + super(props);
38 + this.state = {
39 + script: ''
45 } 40 }
41 + }
46 42
47 - // Send script to server && Move Next URL 43 + stateRefresh = () => {
48 - handleScriptSubmit = (e) => { 44 + this.setState({
49 - console.log(this.script); // test 45 + script: '',
50 - } 46 + });
47 + this.callApi()
48 + .then(res => this.setState({script: res}))
49 + .catch(err => console.log(err));
50 + }
51 51
52 - render() { 52 + callApi = async () => {
53 - const { classes } = this.props; 53 + const response = await fetch('/api/script');
54 - return ( 54 + const body = await response.json();
55 - <Fragment> 55 + return body;
56 - <Typography className={classes.title} variant="h6" color="inherit" noWrap>์Œ์„ฑ์— ๋งž์ถฐ ๋Œ€๋ณธ์„ ํ™”๋ฉด์— ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กฌํ”„ํ„ฐ ์„œ๋น„์Šค</Typography> 56 + }
57 - <Paper className={classes.paper} elevation={3}> 57 +
58 - <TextField id="outlined-textarea" label="Script๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." fullWidth="true" rows={20} placeholder="Script" multiline variant="outlined" onChange={this.getScript}/> 58 + // Get Script
59 - </Paper> 59 + getScript = (e) => {
60 - <Button className={classes.button} variant="contained" color="primary" size="medium" onClick={this.handleScriptSubmit}>์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.</Button> 60 + this.script = e.target.value;
61 - </Fragment> 61 + }
62 - ); 62 +
63 + // Execute addScript() && Move Next URL
64 + handleScriptSubmit = (e) => {
65 + e.preventDefault()
66 + this.addScript()
67 + .then((response) => {
68 + console.log(response.data);
69 + this.stateRefresh();
70 + })
71 + this.setState({
72 + script: ''
73 + })
74 + this.props.history.push('/prompter');
75 +}
76 +
77 + // Send script to Server
78 + addScript = () => {
79 + const url = '/api/script';
80 + let scriptJSON = { script : this.script };
81 + const config = {
82 + headers: {
83 + 'content-type': 'application/json'
84 + }
63 } 85 }
86 + return post(url, JSON.stringify(scriptJSON), config);
87 +}
88 +
89 + render() {
90 + const { classes } = this.props;
91 + return (
92 + <Fragment>
93 + <Typography className={classes.title} variant="h6" color="inherit" noWrap>์Œ์„ฑ์— ๋งž์ถฐ ๋Œ€๋ณธ์„ ํ™”๋ฉด์— ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กฌํ”„ํ„ฐ ์„œ๋น„์Šค</Typography>
94 + <Paper className={classes.paper} elevation={3}>
95 + <TextField id="outlined-textarea" label="Script๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." fullWidth="true" rows={20} placeholder="Script" multiline variant="outlined" onChange={this.getScript} />
96 + </Paper>
97 + <Button className={classes.button} variant="contained" color="primary" size="medium" onClick={this.handleScriptSubmit}>์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.</Button>
98 + </Fragment>
99 + );
100 + }
64 } 101 }
65 102
66 -export default withStyles(styles)(App);
...\ No newline at end of file ...\ No newline at end of file
103 +export default withStyles(styles)(MainPage);
...\ No newline at end of file ...\ No newline at end of file
......
1 +import React, { Component, Fragment } from 'react';
2 +// import { withStyles, Typography, Paper, Button, TextField} from '@material-ui/core';
3 +
4 +// const styles = theme => ({
5 +// root: {
6 +// '& .MuiTextField-root': {
7 +// margin: theme.spacing(1),
8 +// width: '100%',
9 +// minWidth: 1080
10 +// },
11 +// },
12 +// title: {
13 +// marginTop: theme.spacing.unit * 5,
14 +// textAlign: 'center',
15 +// display: 'none',
16 +// fontSize: '2.0rem',
17 +// [theme.breakpoints.up('sm')]: {
18 +// display: 'block',
19 +// }
20 +// },
21 +// paper: {
22 +// marginTop: theme.spacing.unit * 5,
23 +// marginLeft: theme.spacing.unit * 20,
24 +// marginRight: theme.spacing.unit * 20
25 +// },
26 +// button: {
27 +// marginTop: theme.spacing.unit * 1,
28 +// marginLeft: theme.spacing.unit * 20,
29 +// fontSize: '1rem',
30 +// },
31 +// });
32 +
33 +class PrompterPage extends Component {
34 +
35 + render() {
36 + // const { classes } = this.props;
37 + return (
38 + <Fragment>
39 + <h1>{this.props.script}</h1>
40 + </Fragment>
41 + );
42 + }
43 +}
44 +
45 +// export default withStyles(styles)(PrompterPage);
46 +export default PrompterPage;
...\ No newline at end of file ...\ No newline at end of file
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
1 { 1 {
2 "name": "teleprompter-sst", 2 "name": "teleprompter-sst",
3 - "version": "0.1.0", 3 + "version": "1.0.0",
4 - "private": true, 4 + "description": "",
5 - "dependencies": { 5 + "main": "index.js",
6 - "@material-ui/core": "^4.11.0",
7 - "@testing-library/jest-dom": "^5.11.4",
8 - "@testing-library/react": "^11.1.0",
9 - "@testing-library/user-event": "^12.1.10",
10 - "react": "^17.0.1",
11 - "react-dom": "^17.0.1",
12 - "react-scripts": "4.0.1",
13 - "web-vitals": "^0.2.4"
14 - },
15 "scripts": { 6 "scripts": {
16 - "start": "react-scripts start", 7 + "client": "cd client && yarn start",
17 - "build": "react-scripts build", 8 + "server": "nodemon server.js",
18 - "test": "react-scripts test", 9 + "dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\""
19 - "eject": "react-scripts eject"
20 }, 10 },
21 - "eslintConfig": { 11 + "repository": {
22 - "extends": [ 12 + "type": "git",
23 - "react-app", 13 + "url": "http://khuhub.khu.ac.kr/2016110307/Teleprompter-SST.git"
24 - "react-app/jest" 14 + },
25 - ] 15 + "author": "Dongyoung Kwon <ehddud2468@khu.ac.kr>",
16 + "license": "MIT",
17 + "dependencies": {
18 + "body-parser": "^1.19.0",
19 + "express": "^4.17.1",
20 + "multer": "^1.4.2"
26 }, 21 },
27 - "browserslist": { 22 + "devDependencies": {
28 - "production": [ 23 + "concurrently": "^5.3.0",
29 - ">0.2%", 24 + "nodemon": "^2.0.6"
30 - "not dead",
31 - "not op_mini all"
32 - ],
33 - "development": [
34 - "last 1 chrome version",
35 - "last 1 firefox version",
36 - "last 1 safari version"
37 - ]
38 } 25 }
39 } 26 }
......
1 +const fs = require('fs');
2 +const express = require('express');
3 +const bodyParser = require('body-parser');
4 +const app = express();
5 +const port = process.env.PORT || 5000;
6 +
7 +app.use(bodyParser.json());
8 +app.use(bodyParser.urlencoded({ extended: true}));
9 +
10 +// const data = fs.readFileSync('./database.json');
11 +// const conf = JSON.parse(data);
12 +// const mysql = require('mysql');
13 +
14 +
15 +const multer = require('multer');
16 +
17 +// app.get('/api/customers', (req, res) => {
18 +// connection.query(
19 +// "SELECT * FROM course",
20 +// (err, rows, fields) => {
21 +// res.send(rows);
22 +// }
23 +// );
24 +// });
25 +
26 +// app.get('/api/customers/:id', (req, res) => {
27 +// let sql = 'SELECT * FROM course WHERE id=?';
28 +// let params = [req.params.id];
29 +// connection.query(sql, params,
30 +// (err, rows, fields) => {
31 +// res.send(rows);
32 +// }
33 +// );
34 +// });
35 +let scriptReceived = "";
36 +app.get('/api/script', (req, res) => {
37 + res.send(
38 + scriptReceived
39 + )
40 +});
41 +
42 +
43 +app.post('/api/script', (req, res) => {
44 + scriptReceived = req.body.script;
45 +});
46 +
47 +app.listen(port, () => console.log(`Listening on port ${port}`));
...\ No newline at end of file ...\ No newline at end of file
1 -import React from 'react';
2 -import ReactDOM from 'react-dom';
3 -import './index.css';
4 -import App from './App';
5 -import * as serviceWorker from './serviceWorker';
6 -import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
7 -
8 -const theme = createMuiTheme({
9 - typography: {
10 - fontFamily: '"Noto Sans KR", serif',
11 - }
12 -})
13 -
14 -ReactDOM.render(<MuiThemeProvider theme={theme}><App /></MuiThemeProvider>, document.getElementById('root'));
15 -
16 -// If you want your app to work offline and load faster, you can change
17 -// unregister() to register() below. Note this comes with some pitfalls.
18 -// Learn more about service workers: http://bit.ly/CRA-PWA
19 -serviceWorker.unregister();
20 -
21 -// import React from 'react';
22 -// import ReactDOM from 'react-dom';
23 -// import './index.css';
24 -// import App from './App';
25 -// import reportWebVitals from './reportWebVitals';
26 -
27 -// ReactDOM.render(
28 -// <React.StrictMode>
29 -// <App />
30 -// </React.StrictMode>,
31 -// document.getElementById('root')
32 -// );
33 -
34 -// // If you want to start measuring performance in your app, pass a function
35 -// // to log results (for example: reportWebVitals(console.log))
36 -// // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
37 -// reportWebVitals();
This diff could not be displayed because it is too large.
  • ๋ณ€๊ฒฝ ์‚ฌํ•ญ

    1. Express ์ด์šฉํ•ด์„œ Server ๊ตฌ์ถ•
    2. ์ „์ฒด์ ์ธ Front-end ์ˆ˜์ •
      • react-router-dom ์ด์šฉํ•ด์„œ 2 Page๋กœ ๊ตฌ์„ฑ
      • ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›์€ script๋ฅผ Back-end๋กœ ์ „์†กํ•˜๋„๋ก ๊ตฌํ˜„
    Edited