Skip to content

Commit

Permalink
update all
Browse files Browse the repository at this point in the history
  • Loading branch information
sitek94 committed Dec 24, 2020
1 parent ee20b25 commit bbddeb1
Show file tree
Hide file tree
Showing 24 changed files with 690 additions and 1,315 deletions.
4 changes: 2 additions & 2 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NETLIFY_FUNCTIONS_URL=https://kentcdodds.com/.netlify/functions
ROOT_URL=https://kentcdodds.com
NETLIFY_FUNCTIONS_URL=https://macieksitkowski.com/.netlify/functions
ROOT_URL=https://macieksitkowski.com
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ coverage
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

.netlify

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
12
3 changes: 3 additions & 0 deletions config/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ const colors = {
red: '#E75248',
green: '#17A974',
blue: '#327CDC',
navy_dark: '#0F1B35',
yellow: '#FFB700',
purple: '#8242F6',
purple_dark: '#231c42',
background_light: '#5e31dc',
background_dark: '#1e243a',
}

const theme = {
Expand Down
70 changes: 22 additions & 48 deletions netlify/functions/contact.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
const {URL} = require('url')
const nodemailer = require('nodemailer')
const ow = require('ow')
const unified = require('unified')
const markdown = require('remark-parse')
const remark2rehype = require('remark-rehype')
const doc = require('rehype-document')
const format = require('rehype-format')
const html = require('rehype-stringify')
const ow = require('ow').default
const {username} = require('os').userInfo()

function markdownToHtml(markdownString) {
return unified()
.use(markdown)
.use(remark2rehype)
.use(doc)
.use(format)
.use(html)
.process(markdownString)
.then(x => x.contents)
}

const isEmail = ow.string.is(e => /^.+@.+\..+$/.test(e))

function owWithMessage(val, message, validator) {
Expand All @@ -42,7 +24,7 @@ owWithMessage(
)

const transporter = nodemailer.createTransport({
host: 'smtp.mailgun.org',
host: 'smtp.eu.mailgun.org',
port: 587,
secure: false,
auth: {
Expand All @@ -55,15 +37,18 @@ const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
}

async function handler(event) {
// Logger
const runId = Date.now().toString().slice(-5)
// eslint-disable-next-line no-console
const log = (...args) => console.log(runId, ...args)

// CORS
const origin = new URL(event.headers.origin)
const acceptable =
(origin.hostname === 'localhost' && username === 'kentcdodds') ||
origin.hostname === 'kentcdodds.com'
(origin.hostname === 'localhost' && username === 'sitek') ||
origin.hostname === 'macieksitkowski.com'

if (!acceptable) {
return {
Expand All @@ -79,35 +64,25 @@ async function handler(event) {
headers,
}
}
const {name, email, subject, body, ...otherData} = JSON.parse(event.body)

const {email, message, ...otherData} = JSON.parse(event.body)

// Validating
try {
log('> Validating input', ' name: ', name, ' email:', email)
owWithMessage(name, 'The name is required.', ow.string.minLength(1))
owWithMessage(name, 'The name is too long.', ow.string.maxLength(60))
log('> Validating input', ' email: ', email, ' message:', message)
owWithMessage(
email,
'The email is invalid. Please enter a valid email address.',
isEmail,
)
owWithMessage(
subject,
'The subject is too short. Please be more specific.',
ow.string.minLength(5),
)
owWithMessage(
subject,
'The subject is too long. Please shorten it.',
ow.string.maxLength(120),
)
owWithMessage(
body,
'The email body is too short. Give me more details please.',
message,
'The message is too short. Please, give more details.',
ow.string.minLength(40),
)
owWithMessage(
body,
'The email body is too long. Be more succinct please.',
message,
'The message is too long. Please, be more succinct.',
ow.string.maxLength(1001),
)
} catch (e) {
Expand All @@ -121,24 +96,23 @@ async function handler(event) {

const otherDataString = JSON.stringify(otherData, null, 2)

const text = `${body}\n\n---\n\nOther form data:\n\`\`\`\n${otherDataString}\n\`\`\`\n`
const sender = `"${name}" <${email}>`
const text = `${message}\n\n---\n\nOther form data:\n\`\`\`\n${otherDataString}\n\`\`\`\n`
const sender = email

const message = {
const mail = {
from: sender,
to: `"Kent C. Dodds" <me@kentcdodds.com>`,
subject,
to: `"Maciek Sitkowski" <msitkowski94@gmail.com>`,
subject: `Email from ${sender}`,
text,
html: await markdownToHtml(text),
}

try {
log('> Sending...')
await transporter.verify()
await transporter.sendMail(message)
await transporter.sendMail(mail)
log('> Send success!')
} catch (error) {
log('> Send failure!', error.message)
log('> Send failure!', error, error.message)
return {
statusCode: 500,
body: JSON.stringify({message: error.message}),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"http-proxy-middleware": "^1.0.6",
"lodash": "^4.17.20",
"match-sorter": "^6.0.2",
"nodemailer": "^6.4.16",
"ow": "^0.20.0",
"nodemailer": "^6.4.17",
"ow": "^0.21.0",
"polished": "^4.0.5",
"prism-react-renderer": "^1.1.1",
"prism-themes": "^1.5.0",
Expand Down
6 changes: 5 additions & 1 deletion src/components/big-hero.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ function Hero({
color: ${theme.colors.white};
}
width: 100%;
background: linear-gradient(-213deg, #5e31dc 0%, #3155dc 100%);
background: linear-gradient(
-213deg,
${theme.colors.background_light} 0%,
${theme.colors.background_dark} 100%
);
z-index: 0;
position: relative;
align-items: center;
Expand Down
Loading

0 comments on commit bbddeb1

Please sign in to comment.