# Install Cosmic CLI
npm i -g cosmic-cli
# Login to your Cosmic JS account
cosmic login
# Installs example content to a new or existing Bucket and downloads the app locally
cosmic init serverless-starter
cd serverless-starter
# Install Cosmic CLI
npm i -g cosmic-cli
# Login to your Cosmic JS account
cosmic login
# Installs example content to a new or existing Bucket and downloads the app locally
cosmic init vue-starter
cd vue-starter
# Install Cosmic CLI
npm i -g cosmic-cli
# Login to your Cosmic JS account
cosmic login
# Installs example content to a new or existing Bucket and downloads the app locally
cosmic init gatsby-starter
cd gatsby-starter
# Install Cosmic CLI
npm i -g cosmic-cli
# Login to your Cosmic JS account
cosmic login
# Installs example content to a new or existing Bucket and downloads the app locally
cosmic init react-starter
cd react-starter
This file contains hidden or 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
// section-list.js | |
import TeamSection from './sections/team' | |
import SignupSection from './sections/signup' | |
export default ({ sections }) => ( | |
<div> | |
{ | |
sections.map(section => { | |
if (section.metadata.team) | |
return <TeamSection section={section} /> | |
if (section.metadata.cta) |
This file contains hidden or 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
// page.js | |
import SectionList from './section-list' | |
export default ({ page }) => ( | |
<div> | |
<h1>{page.title}</h1> | |
<div dangerouslySetInnerHTML={{__html: page.content}}></div> | |
<SectionList sections={page.metadata.sections}/> | |
</div> | |
) |
This file contains hidden or 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
const serverless = require('serverless-http') | |
const express = require('express') | |
const app = express() | |
const PORT = process.env.PORT || 3000 | |
const Cosmic = require('cosmicjs') | |
const api = Cosmic() | |
const COSMIC_BUCKET = process.env.COSMIC_BUCKET || 'node-starter' | |
const COSMIC_READ_KEY = process.env.COSMIC_READ_KEY || '' | |
let stage_path = 'dev/' | |
if (process.env.STAGE === 'local') |
This file contains hidden or 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
# serverless.yml | |
service: cosmic-serverless | |
provider: | |
name: aws | |
runtime: nodejs6.10 | |
stage: dev | |
region: us-east-1 | |
environment: |
This file contains hidden or 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
module.exports = async function(req, res) { | |
const Cosmic = require('cosmicjs') | |
const sgMail = require('@sendgrid/mail') | |
const async = require('async') | |
sgMail.setApiKey(process.env.SENDGRID_API_KEY) | |
const api = Cosmic() | |
const bucket = api.bucket({ | |
slug: 'story-licensing', | |
write_key: process.env.COSMIC_WRITE_KEY | |
}) |
This file contains hidden or 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
module.exports = function(req, res) { | |
const Cosmic = require('cosmicjs') | |
const api = Cosmic() | |
const bucket = api.bucket({ | |
slug: 'app-bucket-slug', | |
write_key: process.env.COSMIC_WRITE_KEY | |
}) | |
bucket.addObject({ | |
title: 'Lead - ' + (new Date()), | |
type_slug: 'leads', |