first commit
This commit is contained in:
parent
2430371884
commit
a1c86e9cfb
13 changed files with 669 additions and 0 deletions
54
js/index.js
Normal file
54
js/index.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
const InMemoryWorkshop = require("./inMemoryWorkshop")
|
||||
const path = require("path")
|
||||
const ejs = require('ejs')
|
||||
// set the view engine to ejs
|
||||
app.set('view engine', 'ejs');
|
||||
app.set('views', path.join(__dirname, '..', '/ejs'));
|
||||
app.use(express.static(path.join(__dirname , '..', 'css')));
|
||||
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
InMemoryWorkshop.getWorkshopList()
|
||||
.then(workshops => {
|
||||
res.render("index", {
|
||||
workshops: workshops
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/workshop', function (req, res) {
|
||||
res.render('workshop')
|
||||
})
|
||||
|
||||
app.post('/workshop', function (req, res) {
|
||||
const name = req.body.name
|
||||
const description = req.body.description
|
||||
InMemoryWorkshop.addWorkshop(name, description).then(() => {
|
||||
res.render('index')
|
||||
})
|
||||
.catch(e =>ejs.send(e.message))
|
||||
})
|
||||
|
||||
app.get('/workshop/:name', function (req, res) {
|
||||
const workshopName = req.params.name
|
||||
InMemoryWorkshop.getWorkshopByName(workshopName)
|
||||
.then(workshop => {
|
||||
res.render('ejs/workshop', workshop)
|
||||
})
|
||||
.catch(e =>ejs.send(e.message))
|
||||
})
|
||||
|
||||
app.post('/remove-workshop', function (req, res) {
|
||||
res.status(500).send("TODO")
|
||||
})
|
||||
|
||||
app.post('/update-workshop', function(req, res) {
|
||||
res.status(500).send("TODO")
|
||||
})
|
||||
|
||||
app.listen(3000, function () {
|
||||
console.log('Workshop app listening on port 3000!')
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue