Skip to content

Instantly share code, notes, and snippets.

View mikepfeiffer's full-sized avatar
🏠
Working from home

Mike Pfeiffer mikepfeiffer

🏠
Working from home
View GitHub Profile
FROM ubuntu:16.04
# Install dependencies
RUN apt-get update
RUN apt-get -y install apache2
# Install apache and write hello world message
RUN echo 'Hello World!' > /var/www/html/index.html
# Configure apache
@mikepfeiffer
mikepfeiffer / index.js
Created December 15, 2018 20:00
Azure Function Code Sample
module.exports = async function (context, req) {
if (req.body.email) {
var email = {
from: {
email: req.body.email
},
subject: "Contact form submission from: " + req.body.name,
content: [{
type: 'text/plain',
value: req.body.message
@mikepfeiffer
mikepfeiffer / function.json
Created December 15, 2018 20:10
Function.json file for Azure Serverless App Demo
{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
@mikepfeiffer
mikepfeiffer / index.js
Created December 16, 2018 18:05
Default HttpTrigger Code Sample for Azure Function (JavaScript)
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
if (req.query.name || (req.body && req.body.name)) {
context.res = {
// status: 200, /* Defaults to 200 */
body: "Hello " + (req.query.name || req.body.name)
};
}
else {
@mikepfeiffer
mikepfeiffer / index.html
Created December 16, 2018 19:29
Front-end for a Serverless Web App Demo on Azure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello World</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M"
crossorigin="anonymous">
@mikepfeiffer
mikepfeiffer / submitMessage.js
Created December 16, 2018 19:33
Client side code that uses fetch API to submit a form
function submitMessage(e) {
e.preventDefault();
let name = document.getElementById('name').value;
fetch('<YOUR FUNCTION URL GOES HERE>', {
method: 'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-type': 'application/json'
},
@mikepfeiffer
mikepfeiffer / processResponse.js
Created December 16, 2018 19:33
Client side code that processes the response from a demo Azure function
function processResponse(response) {
if (response.status === 200) {
output =
`
<div class="alert alert-success" role="alert">
Hello, ${document.getElementById('name').value}! It's nice to meet you!
</div>
`;
document.getElementById('output').innerHTML = output;
} else {
@mikepfeiffer
mikepfeiffer / Dockerfile
Created December 26, 2018 19:42
Dockerfile for a bare bones Node & Express app
FROM node:alpine
WORKDIR /usr/app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]
@mikepfeiffer
mikepfeiffer / app.js
Created December 26, 2018 21:12
Simple Node Demo App
const config = require('./config');
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World v2!');
});
app.listen(config.port, () => {
@mikepfeiffer
mikepfeiffer / apache.sh
Created January 26, 2019 19:43
EC2 Bootstrap Script for Apache
#!/bin/bash
yum update -y
yum install -y httpd
echo '<h1>Hello World</h1>' > /var/www/html/index.html
systemctl start httpd
systemctl enable httpd