-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (49 loc) · 1.14 KB
/
Copy pathindex.js
File metadata and controls
59 lines (49 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const koa = require("koa");
const json = require("koa-json");
const koaRouter = require("koa-router");
const render = require("koa-ejs");
const bodyparser = require("koa-bodyparser");
const path = require("path");
const app = new koa();
const port = 5000;
app.use(json());
app.use(bodyparser());
const router = new koaRouter();
const wells = [
"SE EUREKA UNIT",
"CHRISTENSEN",
"VELMA",
"GRAY",
"NORTH CARMEN RED FORK UNIT",
"LESLIE",
"MEANS 'C'",
"LSB MCCRADY",
];
// set router middleware
app.use(router.routes()).use(router.allowedMethods());
render(app, {
root: path.join(__dirname, "views"),
layout: "layout",
viewExt: "html",
cache: false,
debug: false,
});
router.get("/", async (ctx) => {
await ctx.render("index", {
title: "Underground Injection Control Wells ",
wells: wells,
});
});
router.get("/addwell", async (ctx) => {
await ctx.render("add");
});
router.post("/addwell", addWell);
async function addWell(ctx) {
const body = ctx.request.body;
const well = body.well.toUpperCase();
wells.push(well);
ctx.redirect("/");
}
app.listen(port, () => {
console.log(`app started on port ${port}`);
});