Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박선진
/
video-emergency-detection
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
3
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박선진
2020-06-21 18:57:21 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
83fcebfaf946b374ac1e8572eba7e383235db8d2
83fcebfa
1 parent
c607dcf2
프론트, 백앤드 연동
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
10 deletions
Back-end/apiRouter.js
Back-end/server.js
Front-end/src/pages/videoAnalysis/VideoAnalysis.js
Back-end/apiRouter.js
View file @
83fcebf
const
express
=
require
(
'express'
);
const
router
=
express
.
Router
();
const
bodyParser
=
require
(
'body-parser'
);
router
.
post
(
'/videoResult'
,
function
(
req
,
res
)
{
file
=
req
.
body
[
0
].
preview
.
split
(
','
)[
1
];
console
.
log
(
file
.
length
);
router
.
get
(
'/data'
,
function
(
req
,
res
)
{
return
res
.
json
({
data
:
'myData'
});
});
module
.
exports
=
router
;
\ No newline at end of file
...
...
Back-end/server.js
View file @
83fcebf
...
...
@@ -3,9 +3,14 @@ const express = require('express');
const
app
=
express
();
const
api
=
require
(
'./apiRouter'
);
const
cors
=
require
(
'cors'
);
const
bodyParser
=
require
(
'body-parser'
);
app
.
use
(
cors
());
app
.
use
(
bodyParser
.
json
({
limit
:
'100mb'
}));
app
.
use
(
bodyParser
.
urlencoded
({
limit
:
'100mb'
,
extended
:
true
}));
app
.
use
(
bodyParser
());
app
.
use
(
'/api'
,
api
);
const
port
=
300
1
;
const
port
=
300
2
;
app
.
listen
(
port
,
()
=>
console
.
log
(
`노드서버 시작 :
${
port
}
`
));
...
...
Front-end/src/pages/videoAnalysis/VideoAnalysis.js
View file @
83fcebf
...
...
@@ -16,6 +16,7 @@ class Dashboard extends React.Component {
super
(
props
);
this
.
onChangeInputVideo
=
this
.
onChangeInputVideo
.
bind
(
this
);
this
.
onClickSaveVideo
=
this
.
onClickSaveVideo
.
bind
(
this
);
// this.analysisVideo = this.analysisVideo.bind(this);
this
.
state
=
{
videoFiles
:
[],
videoAnalysisResult
:
null
...
...
@@ -40,16 +41,24 @@ class Dashboard extends React.Component {
e
.
preventDefault
();
console
.
log
(
this
.
state
.
videoFiles
);
console
.
log
(
"upload video"
);
// post request
fetch
(
'http://localhost:3001/api/data'
)
fetch
(
'http://localhost:3002/api/videoResult'
,{
method
:
'POST'
,
mode
:
'cors'
,
cache
:
'no-cache'
,
credentials
:
'same-origin'
,
headers
:
{
'Content-Type'
:
'application/json'
,
},
redirect
:
'follow'
,
referrer
:
'no-referrer'
,
body
:
JSON
.
stringify
(
this
.
state
.
videoFiles
)
})
.
then
(
res
=>
res
.
json
())
.
then
(
data
=>
this
.
setState
({
videoAnalysisResult
:
data
}))
console
.
log
(
this
.
state
.
videoAnalysisResult
);
this
.
setState
({
videoFiles
:[],
});
}
static
propTypes
=
{
...
...
@@ -58,6 +67,8 @@ class Dashboard extends React.Component {
};
render
()
{
console
.
log
(
"render"
)
console
.
log
(
this
.
state
.
videoFiles
)
return
(
<
div
>
<
h1
className
=
"page-title"
>
Video
Analysis
<
small
><
small
>
Performance
<
/small></
small
><
/h1
>
...
...
@@ -107,4 +118,23 @@ function mapStateToProps(state) {
}
}
export
default
connect
(
mapStateToProps
)(
Dashboard
);
function
postData
(
url
=
''
,
data
=
{})
{
// Default options are marked with *
return
fetch
(
url
,
{
method
:
'POST'
,
// *GET, POST, PUT, DELETE, etc.
mode
:
'cors'
,
// no-cors, cors, *same-origin
cache
:
'no-cache'
,
// *default, no-cache, reload, force-cache, only-if-cached
credentials
:
'same-origin'
,
// include, *same-origin, omit
headers
:
{
'Content-Type'
:
'application/json'
,
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect
:
'follow'
,
// manual, *follow, error
referrer
:
'no-referrer'
,
// no-referrer, *client
body
:
JSON
.
stringify
(
data
),
// body data type must match "Content-Type" header
})
.
then
(
response
=>
response
.
json
());
// parses JSON response into native JavaScript objects
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment