Last active
October 1, 2017 14:53
-
-
Save pinne/0ad63af9b979374a241238098b2d092d 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
let contentful = require('contentful') | |
const space = 'kl86qt22vgc9' | |
const accessToken = 'faa977ce007881a00f698b518482190e13c037b0b1011766101aad9c6bb5f107' | |
let client = contentful.createClient({ space, accessToken }) | |
async function fetchEntry (entry) { | |
try { | |
const reply = await client.getEntry(entry) | |
return reply.fields | |
} catch (error) { | |
return { | |
'Status code': error.response.status, | |
'Error message': error.message | |
} | |
} | |
} | |
module.exports.fetchEntry = fetchEntry |
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
let express = require('express') | |
let { fetchEntry } = require('./contentful') | |
const PORT = 3000 | |
const app = express() | |
app.get('/', (req, res) => { | |
res.send('Hello, World!') | |
}) | |
app.get('/about', (req, res) => { | |
fetchEntry('3ESKTo0plSs4UUEee8gCGy') | |
.then(contentResponseBody => res.send(contentResponseBody.about.toString())) | |
}) | |
app.listen(PORT, () => console.log(`Example app listening on port ${PORT}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment