What this will cover
- Host a static website at S3
- Redirect
www.website.com
towebsite.com
- Website can be an SPA (requiring all requests to return
index.html
) - Free AWS SSL certs
- Deployment with CDN invalidation
const url = 'https://api.example.com/v1/sse'; | |
const accessToken = 'test'; | |
fetch(url, { | |
headers: { | |
Authorization: `Bearer ${accessToken}`, | |
}, | |
}) | |
.then(response => { | |
if (response.ok && response.body) { | |
reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); |
'use strict'; | |
const http = require('http'); | |
exports.handler = (event, context, callback) => { | |
const request = event.Records[0].cf.request; | |
const response = event.Records[0].cf.response; | |
if (response.status == 404) { | |
const domainHash = request.headers['x-domain-hash'] && request.headers['x-domain-hash'][0].value; |
exports.handler = (event, context, callback) => { | |
const request = event.Records[0].cf.request; | |
const headers = request.headers; | |
const host = headers.host[0].value; | |
const hash = /([0-9a-z-]+)\.m\.verybuy\.io/.exec(host) | |
if (hash && hash[1]) { | |
headers['X-Domain-Hash'] = [{ |
'use strict'; | |
exports.handler = (event, context, callback) => { | |
const request = event.Records[0].cf.request; | |
const headers = request.headers; | |
const domainHash = headers['x-domain-hash'] && headers['x-domain-hash'][0].value; | |
if (domainHash) { | |
request.uri = '/' + domainHash + request.uri; | |
} | |
return callback(null, request); |
'use strict'; | |
const customUserAgentHeaderName = 'x-is-bot'; | |
exports.handler = (event, context, callback) => { | |
const request = event.Records[0].cf.request; | |
const headers = request.headers; | |
const userAgent = headers['user-agent'][0].value; | |
headers[customUserAgentHeaderName] = [{ |
'use strict'; | |
const https = require('https'); | |
const BASE_URL_RENDERER = 'YOUR_PRERENDER_SERVER?url='; | |
exports.handler = (event, context, callback) => { | |
const request = event.Records[0].cf.request; | |
const response = event.Records[0].cf.response; | |
const headers = response.headers; | |
'use strict'; | |
exports.handler = (event, context, callback) => { | |
const request = event.Records[0].cf.request; | |
const headers = request.headers; | |
let SHOULD_PRERENDER = false; | |
let IsBot = request.headers['x-is-bot'][0].value === 'true'; | |
SHOULD_PRERENDER = IsBot; |
// > node index.js 'https://store.line.me/stickershop/product/11383/zh-Hant' | |
const puppeteer = require('puppeteer') ; | |
const fs = require('fs'); | |
const http = require('https'); | |
const process = require('process'); | |
var url = process.argv[2]; | |
(async () => { | |
const timeout = 30000; |
import React, { PropTypes, Component } from 'react'; | |
class Checkbox extends Component { | |
static propTypes = { | |
indeterminate: PropTypes.bool, | |
}; | |
componentDidUpdate() { | |
if (typeof this.props.indeterminate !== 'undefined') { | |
this.checkbox.indeterminate = this.props.indeterminate; |