Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
eue
Commits
f967f7cd
Commit
f967f7cd
authored
Jan 26, 2021
by
KangMin An
Browse files
Add Data Input form, routes, routers, controls.
parent
e573eb20
Changes
9
Show whitespace changes
Inline
Side-by-side
server/src/app.js
View file @
f967f7cd
...
...
@@ -5,9 +5,12 @@ import morgan from "morgan";
import
helmet
from
"
helmet
"
;
import
path
from
"
path
"
;
import
routes
from
"
./routes
"
;
import
globalRouter
from
"
./routers/globalRouter
"
;
import
dataRouter
from
"
./routers/dataRouter
"
;
import
routes
from
"
./rout
es
"
;
import
{
localmiddleware
}
from
"
./middlewar
es
"
;
const
app
=
express
();
...
...
@@ -20,6 +23,11 @@ app.use(bodyParser.json());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
use
(
morgan
(
"
dev
"
));
// local middleware 사용
app
.
use
(
localmiddleware
);
// router 사용
app
.
use
(
routes
.
home
,
globalRouter
);
app
.
use
(
routes
.
data
,
dataRouter
);
export
default
app
;
server/src/controllers/dataController.js
View file @
f967f7cd
export
const
getHome
=
(
req
,
res
)
=>
{
res
.
render
(
"
home
"
,
{
pagename
:
"
Home
"
});
import
routes
from
"
../routes
"
;
export
const
getDataInput
=
(
req
,
res
)
=>
{
res
.
render
(
"
datainput
"
,
{
pagename
:
"
Data Input
"
});
};
export
const
postDataInput
=
(
req
,
res
)
=>
{
res
.
redirect
(
routes
.
home
);
};
server/src/controllers/globalController.js
0 → 100644
View file @
f967f7cd
export
const
getHome
=
(
req
,
res
)
=>
{
res
.
render
(
"
home
"
,
{
pagename
:
"
Home
"
});
};
server/src/middlewares.js
0 → 100644
View file @
f967f7cd
import
routes
from
"
./routes
"
;
export
const
localmiddleware
=
(
req
,
res
,
next
)
=>
{
res
.
locals
.
routes
=
routes
;
next
();
};
server/src/routers/dataRouter.js
0 → 100644
View file @
f967f7cd
import
express
from
"
express
"
;
import
routes
from
"
../routes
"
;
import
{
getDataInput
,
postDataInput
}
from
"
../controllers/dataController
"
;
const
dataRouter
=
express
.
Router
();
dataRouter
.
get
(
routes
.
dataInput
,
getDataInput
);
dataRouter
.
post
(
routes
.
dataInput
,
postDataInput
);
export
default
dataRouter
;
server/src/routers/globalRouter.js
View file @
f967f7cd
import
express
from
"
express
"
;
import
routes
from
"
../routes
"
;
import
{
getHome
}
from
"
../controllers/
data
Controller
"
;
import
{
getHome
}
from
"
../controllers/
global
Controller
"
;
const
globalRouter
=
express
.
Router
();
...
...
server/src/routes.js
View file @
f967f7cd
// Global Routes
const
HOME
=
"
/
"
;
// Data Input
const
DATA
=
"
/data
"
;
const
DATA_INPUT
=
"
/input
"
;
const
DATA_OUTPUT
=
"
/output
"
;
const
routes
=
{
home
:
HOME
,
data
:
DATA
,
dataInput
:
DATA_INPUT
,
dataOutput
:
DATA_OUTPUT
,
};
export
default
routes
;
server/src/views/datainput.pug
0 → 100644
View file @
f967f7cd
block content
.form__container
form(action=routes.data+routes.dataInput, method = "post")
input(type="text", name="temp", require=true, placeholder="Temperature")
input(type="text", name="humi", require=true, placeholder="Humidity")
input(type="text", name="bri", require=true, placeholder="Brightness")
input(type="submit", value="Submit")
\ No newline at end of file
server/src/views/home.pug
View file @
f967f7cd
block content
h1 Hello! This is EUE Server.
\ No newline at end of file
.home-link_container
strong Efficient Usage of Electricity
ul
li
a(href=routes.data+routes.dataInput) 데이터 등록
li
a(href=routes.data+routes.dataOutput) 데이터 출력
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment