Toggle navigation
Toggle navigation
This project
Loading...
Sign in
맹주환
/
take_an_umbrella
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
맹주환
2021-12-09 01:51:15 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2f1ba0751b920d7201086e017d9ca7b213b5faa3
2f1ba075
1 parent
5a8edf5c
Fix Server Settings and test importing JS modules.
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
54 additions
and
32 deletions
.gitignore
client/src/App.js
client/src/setupProxy.js
package-lock.json
package.json
import/Weather.js → router/Weather.js
router/user.js
run_server.js
server/server.js
.gitignore
View file @
2f1ba07
...
...
@@ -42,6 +42,7 @@ bower_components
build/Release
# Dependency directories
client/node_modules/
node_modules/
jspm_packages/
...
...
client/src/App.js
View file @
2f1ba07
...
...
@@ -3,14 +3,17 @@ import {useEffect} from "react";
import
'./App.css'
;
function
App
()
{
console
.
log
(
"ang"
);
const
callApi
=
async
()
=>
{
axios
.
get
(
"/
api
"
).
then
((
res
)
=>
console
.
log
(
res
.
data
.
test
));
axios
.
get
(
"/
test
"
).
then
((
res
)
=>
console
.
log
(
res
.
data
.
test
));
};
useEffect
(()
=>
{
callApi
();
},
[]
);
},);
return
<
div
>
test
<
/div>
;
return
(
<
div
>
test
<
/div>
)
;
}
export
default
App
;
\ No newline at end of file
...
...
client/src/setupProxy.js
View file @
2f1ba07
...
...
@@ -2,8 +2,10 @@ const proxy = require('http-proxy-middleware');
module
.
exports
=
function
(
app
)
{
app
.
use
(
proxy
.
createProxyMiddleware
(
'/api'
,
{
target
:
'http://localhost:5000/'
proxy
.
createProxyMiddleware
(
'/'
,
{
target
:
'http://localhost:5000/'
,
changeOrigin
:
true
})
);
};
\ No newline at end of file
...
...
package-lock.json
View file @
2f1ba07
This diff is collapsed. Click to expand it.
package.json
View file @
2f1ba07
...
...
@@ -5,8 +5,13 @@
"start"
:
"concurrently --kill-others-on-fail
\"
npm run server
\"
\"
npm run client
\"
"
},
"dependencies"
:
{
"body-parser"
:
"^1.19.0"
,
"concurrently"
:
"^6.4.0"
,
"cors"
:
"^2.8.5"
,
"express"
:
"^4.17.1"
,
"nodemon"
:
"^2.0.15"
"moment"
:
"^2.29.1"
,
"moment-timezone"
:
"^0.5.34"
,
"nodemon"
:
"^2.0.15"
,
"request"
:
"^2.88.2"
}
}
...
...
import
/Weather.js
→
router
/Weather.js
View file @
2f1ba07
const
express
=
require
(
'express'
);
const
router
=
express
.
Router
();
const
request
=
require
(
'request'
);
const
moment
=
require
(
'moment'
);
require
(
'moment-timezone'
);
...
...
@@ -43,14 +45,20 @@ function get_base_time() // 시간 추출 함수
return
time
}
request
({
url
:
url
+
queryParams
,
method
:
'GET'
},
function
(
error
,
response
,
body
)
{
console
.
log
(
'Status'
,
response
.
statusCode
);
console
.
log
(
'Headers'
,
JSON
.
stringify
(
response
.
headers
));
console
.
log
(
'Reponse received'
,
body
);
});
router
.
get
(
"/"
,
(
req
,
res
)
=>
{
request
(
{
url
:
url
+
queryParams
,
method
:
'GET'
,
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
'Status'
,
response
.
statusCode
);
console
.
log
(
'Headers'
,
JSON
.
stringify
(
response
.
headers
));
console
.
log
(
'Reponse received'
,
body
);
}
);
});
module
.
exports
=
router
;
//
// (사용 예)
...
...
router/user.js
0 → 100644
View file @
2f1ba07
const
express
=
require
(
"express"
);
const
router
=
express
.
Router
();
router
.
get
(
"/"
,
function
(
req
,
res
,
next
)
{
res
.
json
([
{
id
:
1
,
username
:
"VictorOladipo"
},
{
id
:
2
,
username
:
"RussellWstbrook"
},
]);
});
module
.
exports
=
router
;
\ No newline at end of file
run_server.js
deleted
100644 → 0
View file @
5a8edf5
// 서비스 제공을 위한 html 홈페이지를 express로 구현하기 (기본적인 뼈대)
var
express
=
require
(
'express'
)
var
app
=
express
();
// express 선언
const
port
=
10000
//임의의 포트 10000
// request 와 response 라는 인자를 줘서 콜백 함수를 만든다.
// localhost:port 브라우저에 res.sendFile() 내부의 파일이 띄워진다.
app
.
use
(
express
.
static
(
__dirname
+
"/html"
));
app
.
get
(
'/'
,
function
(
req
,
res
)
{
res
.
sendFile
(
__dirname
+
"/html/index.html"
)
})
//임의의 포트 10000, 접속 주소 localhost:10000/
app
.
listen
(
port
,
function
(){
console
.
log
(
'서버 구동중 port : %d'
,
port
);
});
\ No newline at end of file
server/server.js
View file @
2f1ba07
...
...
@@ -2,8 +2,17 @@ const express = require('express');
const
app
=
express
();
const
port
=
5000
;
const
test
=
require
(
'../router/test'
);
const
weather
=
require
(
'../router/Weather'
);
const
user
=
require
(
'../router/user'
);
const
bodyParser
=
require
(
'body-parser'
);
const
cors
=
require
(
'cors'
);
app
.
use
(
cors
());
app
.
use
(
"/test"
,
test
);
app
.
use
(
"/weather"
,
weather
);
app
.
use
(
"/user"
,
user
);
app
.
use
(
bodyParser
.
json
());
app
.
use
(
"/api"
,
test
);
app
.
listen
(
port
,
()
=>
console
.
log
(
'Server is running on :'
,
port
));
\ No newline at end of file
...
...
Please
register
or
login
to post a comment