GithubHelp home page GithubHelp logo

contentful / the-example-app.nodejs Goto Github PK

View Code? Open in Web Editor NEW
430.0 22.0 1.2K 6.71 MB

Example app for Contentful in node.js

Home Page: https://the-example-app-nodejs.contentful.com/

License: MIT License

JavaScript 59.31% Dockerfile 0.19% Shell 1.35% Pug 39.15%
contentful nodejs express docker heroku

the-example-app.nodejs's Introduction

Note: This repo is no longer officially maintained as of Jan, 2023. Feel free to use it, fork it and patch it for your own needs.

The node.js example app

CircleCI

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.

Screenshot of the example app

You can see a hosted version of The node.js example app on Heroku.

What is Contentful?

Contentful provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.

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

Clone the repo and install the dependencies.

git clone https://github.com/contentful/the-example-app.nodejs.git
cd the-example-app.nodejs
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 example content model the-example-app. 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?editorial_features=enabled 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:

Deploy

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

the-example-app.nodejs's People

Contributors

andreascful avatar axe312ger avatar cachrisman avatar dborsatto avatar dependabot[bot] avatar dlitvakb avatar floelhoeffel avatar khaledgarbaya avatar loudmouth avatar mariobodemann avatar muescha avatar naretini avatar roblinde avatar shm avatar trevoreyre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

the-example-app.nodejs's Issues

pm2 run background

I have just install pm2, but when I using pm start background

pm2 start:dev // not work

Could you help how to start application with pm2 ?
Thanks & Regards

Deploy in firebase or netlify

Query, what would be the equivalent command to "npm run build" to be able to implement in a service like Firebase Hosting or Netlify, when adding the repository to Netlify and attaching the npm run start: the command throws me a record with https: localhost: 3000

If someone knows or can help me, or if you do the same, do a deployment in Docker

Slow responsiveness on Website

Hi! Just wondering if there's a reason the content is a tiny bit laggy on the example website. eg when switching between Home and Courses there's a short but noticeable delay. Is this because the website isn't being served via a CDN like most other sites? Just curious

Change meta prop for twitter:card

The meta property for twitter:card has the wrong attribute.

Right now it's: meta(name='twitter:card' value='This is The Example App, an application built to serve you as a reference while building your own applications using Contentful.')

Should be: meta(name='twitter:card' content='This is The Example App, an application built to serve you as a reference while building your own applications using Contentful.')

Leftover dummy text

Hey,

on the settings page there are still some left over dummy texts: Some help text we still need to define Should we remove/update them?
screenshot from 2017-10-05 12-30-40

Rename repo to `the-example-app.js`

Since we agreed on our new name, at somepoint we should reflect it in the name of the repository/internal mentions.

Suggestion: https://github.com/contentful/the-example-app.js

manual described updating variables.env file but was not read by frontend unless forced

actions taken:

-followed step 6 from README.md
-verified that variables.env contain correct api tokens
-frontend kept using default variables from first start
-needed to manually unlink first on /settings (not listed as required action in README.md) as it kept saying preview token was invalid

can be reproduced by temporarily moving variables.env > variables.tmp

  • frontend will persistently use variables set in frontend from previous session.

developer experience can be improved by displaying on the server (e.g. npm run start:dev) which variables it is using making the connection to the contentful servers. Additionally a Step 8 "verify on /settings that your credentials are being used"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.