forked from web/foundation
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
68 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"es6": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
#!/usr/bin/env node | ||
|
||
var Koa = require("koa") | ||
var Router = require("koa-router"); | ||
var stat = require("koa-static"); | ||
var bodyParser = require("koa-bodyparser"); | ||
var handlebars = require("koa-hbs-renderer"); | ||
const Koa = require('koa') | ||
const Router = require('koa-router') | ||
const stat = require('koa-static') | ||
const bodyParser = require('koa-bodyparser') | ||
const handlebars = require('koa-hbs-renderer') | ||
|
||
var app = new Koa(); | ||
var router = new Router(); | ||
app.use(stat ("public")); | ||
app.use(bodyParser()); | ||
app.use(handlebars({ paths: { views: __dirname + "/views" } })); | ||
app.use(router.routes()); | ||
const app = new Koa() | ||
const router = new Router() | ||
app.use(stat('public')) | ||
app.use(bodyParser()) | ||
app.use(handlebars({ paths: { views: `${__dirname }/views` } })) | ||
app.use(router.routes()) | ||
|
||
var port = 8080 | ||
const port = 8080 | ||
|
||
const List = require('./modules/list').List | ||
const list = new List() | ||
|
||
router.get("/", async function(ctx) { | ||
try { | ||
var items = list.getAll() // you will need to REPLACE this with a call to the 'list' object!!! | ||
console.log(items) | ||
var data = {items} | ||
ctx.render('home', data); | ||
} catch(err) { | ||
console.log(err.message); | ||
ctx.render('home', {msg: err.message}); | ||
} | ||
}); | ||
|
||
router.post("/", function(ctx) { | ||
try { | ||
var body = ctx.request.body; | ||
console.log(body) | ||
list.add(body.item, body.qty)// you will need to add a call to the 'list' object!!! | ||
ctx.redirect("/"); | ||
} catch(err) { | ||
console.log(err.message); | ||
ctx.redirect("/?msg=" + err.message); | ||
} | ||
}); | ||
|
||
router.get("/delete/:key", function(ctx) { | ||
try { | ||
console.log(`key: ${ctx.params.key}`); | ||
list.delete(ctx.params.key)// you will need to add a call to the 'list' object!!! | ||
ctx.redirect('/?msg=item deleted'); | ||
} catch(err) { | ||
console.log(err.message); | ||
ctx.redirect("/" + err.message); | ||
} | ||
}); | ||
|
||
module.exports = app.listen(port, async function() { | ||
console.log('listening on port ' + port); | ||
}); | ||
router.get('/', async(ctx) => { | ||
try { | ||
const items = list.getAll() // you will need to REPLACE this with a call to the 'list' object!!! | ||
console.log(items) | ||
const data = {items} | ||
ctx.render('home', data) | ||
} catch(err) { | ||
console.log(err.message) | ||
ctx.render('home', {msg: err.message}) | ||
} | ||
}) | ||
|
||
router.post('/', (ctx) => { | ||
try { | ||
const body = ctx.request.body | ||
console.log(body) | ||
list.add(body.item, body.qty)// you will need to add a call to the 'list' object!!! | ||
ctx.redirect('/') | ||
} catch(err) { | ||
console.log(err.message) | ||
ctx.redirect(`/?msg=${ err.message}`) | ||
} | ||
}) | ||
|
||
router.get('/delete/:key', (ctx) => { | ||
try { | ||
console.log(`key: ${ctx.params.key}`) | ||
list.delete(ctx.params.key)// you will need to add a call to the 'list' object!!! | ||
ctx.redirect('/?msg=item deleted') | ||
} catch(err) { | ||
console.log(err.message) | ||
ctx.redirect(`/${ err.message}`) | ||
} | ||
}) | ||
|
||
module.exports = app.listen(port, async() => { | ||
console.log(`listening on port ${ port}`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -19,7 +19,7 @@ | ||
"koa-views": "^6.2.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^6.5.1", | ||
"eslint": "^6.6.0", | ||
"jsdoc": "^3.6.3" | ||
} | ||
} |