Commit f967f7cd authored by KangMin An's avatar KangMin An
Browse files

Add Data Input form, routes, routers, controls.

parent e573eb20
......@@ -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 "./routes";
import { localmiddleware } from "./middlewares";
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;
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);
};
export const getHome = (req, res) => {
res.render("home", { pagename: "Home" });
};
import routes from "./routes";
export const localmiddleware = (req, res, next) => {
res.locals.routes = routes;
next();
};
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;
import express from "express";
import routes from "../routes";
import { getHome } from "../controllers/dataController";
import { getHome } from "../controllers/globalController";
const globalRouter = express.Router();
......
// 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;
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
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment