Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewisabel committed Jan 15, 2021
0 parents commit 25606cd
Show file tree
Hide file tree
Showing 27 changed files with 192,761 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

# For information on the contents of the container image below, see following Dockerfile:
# https://github.com/microsoft/vscode-dev-containers/tree/v0.43.0/containers/javascript-node-12/.devcontainer/Dockerfile
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-12

# The image referenced above includes a non-root user with sudo access. Add
# the "remoteUser" property to devcontainer.json to use it. On Linux, the container
# user's GID/UIDs will be updated to match your local UID/GID when using the image
# or dockerFile property. Update USER_UID/USER_GID below if you are using the
# dockerComposeFile property or want the image itself to start with different ID
# values. See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG USERNAME=node

# [Optional] Update UID/GID if needed
RUN if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \
groupmod --gid $USER_GID $USERNAME \
&& usermod --uid $USER_UID --gid $USER_GID $USERNAME \
&& chown -R $USER_UID:$USER_GID /home/$USERNAME; \
fi

# *************************************************************
# * Uncomment this section to use RUN instructions to install *
# * any needed dependencies after executing "apt-get update". *
# * See https://docs.docker.com/engine/reference/builder/#run *
# *************************************************************
# ENV DEBIAN_FRONTEND=noninteractive
# RUN apt-get update \
# && apt-get -y install --no-reccomends <your-package-list-here> \
# #
# # Clean up
# && apt-get autoremove -y \
# && apt-get clean -y \
# && rm -rf /var/lib/apt/lists/*
# ENV DEBIAN_FRONTEND=dialog

# Uncomment to default to non-root user
# USER $USER_UID
27 changes: 27 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Haikus for june",
"dockerComposeFile": "docker-compose.yml",
"service": "web",
"workspaceFolder": "/workspace",

// Comment out the next line to run as root instead.
"remoteUser": "node",

"forwardPorts": [3000, 5432],

// Use 'settings' to set *default* container specific settings.json values on container create.
// You can edit these settings after create using File > Preferences > Settings > Remote.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
},

// Specifies a command that should be run after the container has been created.
"postCreateCommand": "npm install",

// Add the IDs of extensions you want installed when the container is created in the array below.
"extensions": [
"dbaeumer.vscode-eslint",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg"
]
}
31 changes: 31 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '3'
services:
web:
network_mode: host
build:
context: .
dockerfile: Dockerfile
args:
VARIANT: 12
depends_on:
- db
env_file: ../.env
environment:
NODE_ENV: development
PORT: 3000
HOST: localhost
working_dir: /workspace
volumes:
- ..:/workspace:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

db:
network_mode: host
image: postgres
restart: unless-stopped
env_file: ../.env
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql

34 changes: 34 additions & 0 deletions .devcontainer/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CREATE TABLE haikus (
id SERIAL PRIMARY KEY,
haiku text,
image text,
hearts int
);

INSERT INTO haikus (haiku, image, hearts) VALUES
(
E'rain in seattle,\ndon''t forget an umbrella,\nor it will be gloom',
'puddle_jumper_octodex.jpg',
0
),
(
E'my tunes on repeat,\nit''s time for me to dj,\nhave you heard this one?',
'vinyltocat.jpeg',
0
),
(
E'snow is still falling,\nis it time for apres yet?\nlet''s do one more run',
'snowtocat_final.jpg',
0
),
(
E'beep boop bop beep boop,\ni am robot octocat,\ni think there''s a bug',
'Robotocat.jpeg',
0
),
(
E'Same plot as before,\nSo why is it still awesome?\nI think it''s the hat',
'linktocat.jpg',
0
)
;
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POSTGRES_PASSWORD=pwd
POSTGRES_USER=admin
POSTGRES_DB=work
24 changes: 24 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Node.js CI

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build --if-present
- run: npm test
env:
CI: true
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.js"
}
]
}
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"sqltools.connections": [
{
"previewLimit": 50,
"server": "localhost",
"port": 5432,
"driver": "PostgreSQL",
"name": "localhost",
"database": "work",
"username": "admin",
"password": "pwd"
}
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Haikus for Mona

A basic node / postgres app using an ejs template and a few API endpoints.

### `npm test`

Runs the test suite, which by default executes changes since last commit.

### `npm run build`

Builds for production and deployment.

### `npm run dev`

Run dev server with nodemon

8 changes: 8 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const gulp = require('gulp');
const imagemin = require('gulp-imagemin');

exports.default = () => (
gulp.src('./raw_images/*')
.pipe(imagemin())
.pipe(gulp.dest('./public/images'))
);
26 changes: 26 additions & 0 deletions haikus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"text": "Pulling on my leash,\nTo meet my newest best friend,\nEvery single dog",
"image": "adopted.jpg"
},
{
"text": "Busy time at work,\nSo much to get done today,\nCircle back re: naps",
"image": "sun.jpg"
},
{
"text": "It is a new day,\nWake up, yawn, and downward dog,\nHumans say BIG STRETCH",
"image": "pillow.jpg"
},
{
"text": "The humans are home,\nThey don't ever go outside,\nJune loves quarantine",
"image": "blanket.jpg"
},
{
"text": "Fridge is opening,\nSilly humans look away,\nLunchables bandit",
"image": "visitor.jpg"
},
{
"text": "Sit, down, paw, leave, stay,\nIf I try them all at once,\nGuaranteed a treat",
"image": "sunlight.jpg"
}
]
33 changes: 33 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const { Pool } = require('pg')
app.locals.octicons = require("@primer/octicons");

const pool = new Pool({
user: process.env.POSTGRES_USER,
database: process.env.POSTGRES_DB,
password: process.env.POSTGRES_PASSWORD,
host: process.env.HOST,
port: 5432
});

app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(express.static('public'))
app.set('view engine', 'ejs');

app.get('/', (req, res) => {
pool.query('SELECT * FROM haikus ORDER BY id', (err, haikus) => {
res.render('index', {haikus: haikus.rows});
});
});

app.post('/heart', (req, res) => {
pool.query('UPDATE haikus SET hearts = hearts + 1 WHERE id = $1', [req.body.id], () => {
res.send('Success');
});
});

app.listen(port);
console.log(`Server running on http://localhost:${port}`)
Loading

0 comments on commit 25606cd

Please sign in to comment.