* Production (#44) * test: Fix integration test * fix: Fix Editorial feature * chore(localization): move locales to i18n folder * feat(modules): add image caption and shadow * fix: clarify German translation🇩🇪 * chore(localization): fix typo (#47) * Split first paragraph into sections (#46) * feat(controls): add help text to API dropdown * fix(style): simplify header and fix mobile design * fix(style): simplify footer and fix mobile design * fix(style): update stylesheet and scripts file * test(e2e): adjust tests and make them fail on CI * language fixes * rename labels to use full api name * Refactor entry state toggle (#48) * chore(editorialFeatures): extract editorial features toggle * chore(refactor): rename function to make more contextual sense * Fix breadcrumb and add test for locales (#49) * test(unit): add test to check for locale consistency * fix(breadcrumb): translate lessons route * Change readme url to http from https (#52) * tests(e2e): expect only 2 courses * fix(cookies): fix variable naming and extend to two days maxAge * Change text on next lesson button (#54) * Retranslate advancedLabel * fix(translations): do not break on vim temp files. This is dedicated to JP * fix(analytics): use correct app-id * Add instructions to seed a space to readme (#61) * Change modal text; add link to model's repo to localization files (#57) * fix(links): link correct GH repository * fix(i18n): adjust view on github link label * fix(style): move GitHub link to the left * new screenshot * Update README.md (#63) * Update README.md * Update README.md * Https mistake and Heroku buton * fixup * fixup * feat(heroku): add app.json * docs(README): add linebreak * docs(README): minor adjustments * fix(tracking): add link click tracking to snowplow * Add translation for edit in the web app (#64) * chore(typo): fix error message (#67) * chore(update): remove image rendering on lessons (#65) * chore: Improve error page (#66) * chore: Improve error page * fix: Fix middlware order * fix: Remove console.log * fix: no more duplicate error messges (#71) * fix: Fix middlware order * fix: Remove console.log * feat: Uniq error meassages * fix: fix cli link (#72) * Add instructions to run app as Docker container (#68)
4.7 KiB
The node.js example app
The node.js example app teaches the very basics of how to work with Contentful:
- consume content from the Contentful Delivery and Preview APIs
- model content
- edit content through the Contentful web app
The app demonstrates how decoupling content from its presentation enables greater flexibility and facilitates shipping higher quality software more quickly.
You can see a hosted version of The node.js example app on Heroku.
What is Contentful?
Contentful is content infrastructure for web applications, mobile apps and connected devices. It allows you to create, edit and manage content in the cloud and publish it anywhere via powerful APIs. Contentful offers tools for editorial teams and enabling cooperation between organizations.
Requirements
- Node 8
- Git
- Contentful CLI (only for write access)
Without any changes, this app is connected to a Contentful space with read-only access. To experience the full end-to-end Contentful experience, you need to connect the app to a Contentful space with read and write access. This enables you to see how content editing in the Contentful web app works and how content changes propagate to this app.
Common setup
You can clone the space for this example app to your own Contentful account by using our CLI tool.
contentful space seed -s '<SPACE_ID>' -t the-example-app
If you do not have the Contentful CLI installed you can find instructions on installation and usage here. For more information on the content model check out this repo.
Once you’ve created a space, you can change the credentials in the variables.env. If you don’t feel like changing code immediately, you can also inject credentials via url parameters like so:
Clone the repo and install the dependencies.
git clone https://github.com/contentful/the-example-app.nodejs.git
npm install
Steps for read-only access
To start the express server, run the following
npm run start:dev
Open http://localhost:3000 and take a look around.
Steps for read and write access (recommended)
Step 1: Install the Contentful CLI
Step 2: Login to Contentful through the CLI. It will help you to create a free account if you don't have one already.
contentful login
Step 3: Create a new space
contentful space create --name 'My space for the example app'
Step 4: Seed the new space with the content model. Replace the SPACE_ID with the id returned from the create command executed in step 3
contentful space seed -s '<SPACE_ID>' -t the-example-app
Step 5: Head to the Contentful web app's API section and grab SPACE_ID, DELIVERY_ACCESS_TOKEN, PREVIEW_ACCESS_TOKEN.
Step 6: Open variables.env and inject your credentials so it looks like this
NODE_ENV=development
CONTENTFUL_SPACE_ID=<SPACE_ID>
CONTENTFUL_DELIVERY_TOKEN=<DELIVERY_ACCESS_TOKEN>
CONTENTFUL_PREVIEW_TOKEN=<PREVIEW_ACCESS_TOKEN>
PORT=3000
Step 7: To start the express server, run the following
npm run start:dev
Final Step:
Open http://localhost:3000?enable_editorial_features and take a look around. This URL flag adds an “Edit” button in the app on every editable piece of content which will take you back to Contentful web app where you can make changes. It also adds “Draft” and “Pending Changes” status indicators to all content if relevant.
Deploy to Heroku
You can also deploy this app to Heroku:
Use Docker
You can also run this app as a Docker container:
Step 1: Clone the repo
git clone https://github.com/contentful/the-example-app.nodejs.git
Step 2: Build the Docker image
docker build -t the-example-app.nodejs .
Step 3: Run the Docker container locally:
docker run -p 3000:3000 -d the-example-app.nodejs
If you created your own Contentful space, you can use it by overriding the following environment variables:
docker run -p 3000:3000 \
-e CONTENTFUL_SPACE_ID=<SPACE_ID> \
-e CONTENTFUL_DELIVERY_TOKEN=<DELIVERY_ACCESS_TOKEN> \
-e CONTENTFUL_PREVIEW_TOKEN=<PREVIEW_ACCESS_TOKEN> \
-d the-example-app.nodejs
