当前位置: 首页 > 软件库 > Web应用开发 > >

the-example-app.nodejs

Example app for Contentful in node.js
授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发
软件类型 开源软件
地区 不详
投 递 者 袁博
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

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 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
  • app.use(path,callback)中的callback既可以是router对象又可以是函数;将一个URL路径与一个函数绑定,第一个参数为访问的路径,如果第一参数为空,则表示任何路径都触发这个处理函数;第 二个参数为执行的函数 app.get(path,callback)中的callback只能是函数 当一个路径有多个匹配规则时,使用app.use(),当一个路径只有一个匹配规则时,使用a

  • Node.js for Mobile Apps This is the main repository for Node.js for Mobile Apps, a toolkit for integrating Node.js into mobile applications. Resources for Newcomers This is the central repository for

  • Usage# node [options] [v8 options] [script.js | -e "script"] [arguments] Please see the Command Line Options document for information about different options and ways to run scripts with Node.js. Exam

  • Thanks for taking a look at this already! Could you briefly explain how these environment variables are being used? I'm not the person who discovered the need for those env vars (I mostly just want to

  • 原文地址:http://js8.in/774.html express.js是nodejs的一个MVC开发框架,并且支持jade等多种模板。下面简单来说说express的安装和app.js文件的配置,然后在今后的教程中一步一步使用express.js搭建个聊天室。 安装express.js 如果你安装了npm,安装变得很简单,只需要在终端中运行下面的代码即可: npm install expres

  • 设置静态目录 1 2 app. use (express. static (path.join(__dirname, 'public' ))); //设置模版渲染的js,css,images的静态文件目录 设置模版引擎 1 app. set ( 'view engine' , 'ejs' ); //设置视图模版引擎ejs 设置视图文件存放的地方 1 app. set ( 'views' , pat

  • Now offers a friction-free way to deploy node applications right from the terminal. In this lesson, we'll learn how to use the now CLI to deploy a node application, including the deployment of environ

 相关资料
  • 描述 (Description) Foundation通过使用由Motion UI库创建的过渡类来提供过渡效果。 例子 (Example) 以下示例演示了在Foundation中使用transitions - <!doctype html> <head> <meta charset = "utf-8" /> <meta http-equiv = "x-ua-compa

  • 企业应用开发示例 对于我们的教程,我们将实施化学设备和加工公司的CRM应用程序。 该公司涉及供应商并提供服务。 我们将在整个教程中编写与此示例相关的小代码片段,以详细了解每个概念。 要执行本教程中的代码,您需要创建两个对象:Customer和Invoice对象。 如果您已经知道如何在Salesforce中创建这些对象,则可以跳过下面给出的步骤。 否则,您可以按照下面的分步指南进行操作。 创建客户对

  • 描述: 提供一个如何使用描述项的例子。 Overview(概述) 提供一个如何使用描述项的例子。跟随此标签的文字将显示为高亮代码。 Examples(例子) 注意,一个doclet中可以同时使用多个@example标签。 例如,描述多个示例: /** * Solves equations of the form a * x = b * @example * // returns 2 * g

  • An implementation of the @handsontable/vue component with a readOnly toggle switch and the Vuex state manager implemented. Toggle readOnly for the entire table Vuex store dump: Toggle readOnly for the

  • A simple implementation of the @handsontable/vue component.import Vue from 'vue'; import { HotTable } from '@handsontable/vue'; import Handsontable from 'handsontable'; new Vue({ el: '#example1', data

  • An implementation of the @handsontable/angular wrapper.// app.component.ts import { Component } from '@angular/core'; import * as Handsontable from 'handsontable'; @Component({ selector: 'app-root', t