Skip to content

Instantly share code, notes, and snippets.

View tonyspiro's full-sized avatar
🚀
Building and shipping

Tony Spiro tonyspiro

🚀
Building and shipping
View GitHub Profile
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
})
# serverless.yml
service: cosmic-serverless
provider:
name: aws
runtime: nodejs6.10
stage: dev
region: us-east-1
environment:
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')
// 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>
)
// 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)
# 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
# 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 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 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 node-starter
cd node-starter