Created
June 9, 2018 19:39
-
-
Save lukenetti3/c723cab2a1c7a7a08bbc1204323f5477 to your computer and use it in GitHub Desktop.
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
var bodyParser = require("body-parser"), | |
express = require("express"), | |
app = express(), | |
Cosmic = require("cosmicjs"); | |
var api = Cosmic(); | |
var bucket = api.bucket({ | |
slug: "favorite-book", | |
read_key: "QxlWYVywWwJu94x9vVp3DJFt11OqLIUJRBBp0i4FyqbpvtOOhp" | |
}); | |
app.set("view engine", "ejs"); | |
app.use(express.static("public")); | |
app.use(bodyParser.urlencoded({extended: true})); | |
app.get("/", function(req,res){ | |
res.redirect("/books"); | |
}); | |
app.get("/books", function(req,res){ | |
bucket.getObjects({ | |
}).then(books => { | |
res.render("index", {books: books}); | |
}); | |
}); | |
app.get("/books/:slug", function(req,res){ | |
bucket.getObject({ | |
slug: req.params.slug | |
}).then(book => { | |
res.render("show", {book: book}); | |
}); | |
}); | |
app.listen(process.env.PORT || 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment