Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yamitzky committed Jan 10, 2018
1 parent 8b140e8 commit 99b85c6
Show file tree
Hide file tree
Showing 31 changed files with 13,357 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
@@ -0,0 +1 @@
frontend/node_modules
13 changes: 13 additions & 0 deletions .editorconfig
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
29 changes: 29 additions & 0 deletions Dockerfile
@@ -0,0 +1,29 @@
FROM node:8-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY frontend/package.json /usr/src/app
COPY frontend/yarn.lock /usr/src/app
RUN yarn

COPY frontend /usr/src/app
RUN yarn generate

FROM python:3.6-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY api/requirements.txt /usr/src/app
RUN pip install -r requirements.txt

COPY api /usr/src/app

COPY --from=0 /usr/src/app/dist /usr/share/nginx/html
VOLUME /usr/share/nginx/html

COPY conf /etc/nginx/conf.d
VOLUME /etc/nginx/conf.d

CMD ["python", "api.py"]
22 changes: 22 additions & 0 deletions README.md
@@ -0,0 +1,22 @@
# url-express

> Nuxt.js project
## Build Setup

``` bash
# install dependencies
$ npm install # Or yarn install

# serve with hot reload at localhost:3000
$ npm run dev

# build for production and launch server
$ npm run build
$ npm start

# generate static project
$ npm run generate
```

For detailed explanation on how things work, checkout the [Nuxt.js docs](https://github.com/nuxt/nuxt.js).
13 changes: 13 additions & 0 deletions api/Dockerfile
@@ -0,0 +1,13 @@
FROM python:3.6-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY requirements.txt /usr/src/app
RUN pip install -r requirements.txt

COPY api.py /usr/src/app

EXPOSE 8080

CMD ["python", "api.py"]
69 changes: 69 additions & 0 deletions api/api.py
@@ -0,0 +1,69 @@
import datetime
import os
import urllib.parse

from bottle import route, run, request, abort, response, redirect, hook
import boto3


DEBUG = os.environ.get('DEBUG') == '1'
if DEBUG:
CORS_ALLOW_ORIGIN = os.environ.get('CORS_ALLOW_ORIGIN') or '*'
else:
CORS_ALLOW_ORIGIN = os.environ['CORS_ALLOW_ORIGIN']

if os.environ.get('DYNAMO_ENDPOINT_URL'):
dynamo = boto3.resource('dynamodb', endpoint_url=os.environ['DYNAMO_ENDPOINT_URL'])
else:
dynamo = boto3.resource('dynamodb')
table = dynamo.Table(os.environ.get('DYNAMO_TABLE_NAME', 'url-press'))


@hook('after_request')
def enable_cors():
response.headers['Access-Control-Allow-Origin'] = CORS_ALLOW_ORIGIN
response.headers['Access-Control-Allow-Methods'] = 'PUT, GET, POST, DELETE, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type'


@route('/<:re:.*>', method='OPTIONS')
def options_handler(path=None):
return


@route('/<slug>')
def redirect_url(slug):
item = table.get_item(Key={'id': slug})
if item.get('Item', {}).get('url'):
redirect(item['Item']['url'])
else:
abort(404, f"Not found: {slug}")


@route('/api/urls', method=['GET', 'POST'])
def generate():
if request.method == 'POST':
item = {
'id': urllib.parse.quote_plus(request.json['id']),
'url': request.json['url'],
'timestamp': int(datetime.datetime.now().timestamp())
}
table.put_item(Item=item)
response.status = 201
return item
else:
cursor = request.params.get('cursor')
if cursor:
result = table.scan(ExclusiveStartKey=cursor)
else:
result = table.scan()
items = result['Items']
for item in items:
item['timestamp'] = int(item['timestamp'])
return {
'urls': items,
'cursor': result.get('LastEvaluatedKey')
}


run(host='0.0.0.0', port=8080, debug=DEBUG, reloader=DEBUG)
2 changes: 2 additions & 0 deletions api/requirements.txt
@@ -0,0 +1,2 @@
bottle
boto3
24 changes: 24 additions & 0 deletions conf/nginx.conf
@@ -0,0 +1,24 @@
server {
server_name _;
listen 80;
access_log /dev/stdout;
error_log /dev/stderr warn;

gzip on;
gzip_min_length 1024;
gzip_types application/json;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/index.html @api;
}

location @api {
proxy_pass http://api:8080;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Cache-Control "no-cache, no-store";
}
}
16 changes: 16 additions & 0 deletions docker-compose.override.yml
@@ -0,0 +1,16 @@
version: '3'

services:
dynamo:
image: cnadiminti/dynamodb-local
ports:
- 8000:8000

dynamo-gui:
image: yamitzky/dynamodb-gui
environment:
- DYNAMO_ENDPOINT=http://dynamo:8000
ports:
- 8001:8001
depends_on:
- dynamo
37 changes: 37 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,37 @@
version: '3'

services:
node:
build: frontend
command: sh -c "yarn && yarn dev"
volumes:
- ./frontend:/usr/src/app
- node-volume:/usr/src/app/node_modules
environment:
- API_URL=http://api:8080/api
- API_URL_BROWSER=http://localhost:8080/api
ports:
- 3000:3000
depends_on:
- api

api:
build: api
volumes:
- ./api:/usr/src/app
environment:
- DEBUG=1
- AWS_DEFAULT_REGION=local
- AWS_ACCESS_KEY_ID=dummy
- AWS_SECRET_ACCESS_KEY=dummy
- DYNAMO_ENDPOINT_URL=http://dynamo:8000
ports:
- 8080:8080
depends_on:
- dynamo

dynamo:
image: cnadiminti/dynamodb-local

volumes:
node-volume:
16 changes: 16 additions & 0 deletions frontend/.eslintrc.js
@@ -0,0 +1,16 @@
module.exports = {
root: true,
parser: 'babel-eslint',
env: {
browser: true,
node: true
},
extends: 'standard',
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
rules: {},
globals: {}
}
11 changes: 11 additions & 0 deletions frontend/.gitignore
@@ -0,0 +1,11 @@
# dependencies
node_modules

# logs
npm-debug.log

# Nuxt build
.nuxt

# Nuxt generate
dist
14 changes: 14 additions & 0 deletions frontend/Dockerfile
@@ -0,0 +1,14 @@
FROM node:8-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app
COPY yarn.lock /usr/src/app
RUN yarn

COPY . /usr/src/app

EXPOSE 3000

CMD ["yarn", "dev"]
9 changes: 9 additions & 0 deletions frontend/app.html
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html {{ HTML_ATTRS }}>
<head>
{{ HEAD }}
</head>
<body {{ BODY_ATTRS }}>
{{ APP }}
</body>
</html>
8 changes: 8 additions & 0 deletions frontend/assets/README.md
@@ -0,0 +1,8 @@
# ASSETS

This directory contains your un-compiled assets such as LESS, SASS, or JavaScript.

More information about the usage of this directory in the documentation:
https://nuxtjs.org/guide/assets#webpacked

**This directory is not required, you can delete it if you don't want to use it.**
79 changes: 79 additions & 0 deletions frontend/components/Logo.vue
@@ -0,0 +1,79 @@
<template>
<div class="VueToNuxtLogo">
<div class="Triangle Triangle--two"></div>
<div class="Triangle Triangle--one"></div>
<div class="Triangle Triangle--three"></div>
<div class="Triangle Triangle--four"></div>
</div>
</template>

<style>
.VueToNuxtLogo {
display: inline-block;
animation: turn 2s linear forwards 1s;
transform: rotateX(180deg);
position: relative;
overflow: hidden;
height: 180px;
width: 245px;
}
.Triangle {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
}
.Triangle--one {
border-left: 105px solid transparent;
border-right: 105px solid transparent;
border-bottom: 180px solid #41B883;
}
.Triangle--two {
top: 30px;
left: 35px;
animation: goright 0.5s linear forwards 3.5s;
border-left: 87.5px solid transparent;
border-right: 87.5px solid transparent;
border-bottom: 150px solid #3B8070;
}
.Triangle--three {
top: 60px;
left: 35px;
animation: goright 0.5s linear forwards 3.5s;
border-left: 70px solid transparent;
border-right: 70px solid transparent;
border-bottom: 120px solid #35495E;
}
.Triangle--four {
top: 120px;
left: 70px;
animation: godown 0.5s linear forwards 3s;
border-left: 35px solid transparent;
border-right: 35px solid transparent;
border-bottom: 60px solid #fff;
}
@keyframes turn {
100% {
transform: rotateX(0deg);
}
}
@keyframes godown {
100% {
top: 180px;
}
}
@keyframes goright {
100% {
left: 70px;
}
}
</style>
6 changes: 6 additions & 0 deletions frontend/components/README.md
@@ -0,0 +1,6 @@
# COMPONENTS

The components directory contains your Vue.js Components.
Nuxt.js doesn't supercharge these components.

**This directory is not required, you can delete it if you don't want to use it.**
8 changes: 8 additions & 0 deletions frontend/layouts/README.md
@@ -0,0 +1,8 @@
# LAYOUTS

This directory contains your Application Layouts.

More information about the usage of this directory in the documentation:
https://nuxtjs.org/guide/views#layouts

**This directory is not required, you can delete it if you don't want to use it.**

0 comments on commit 99b85c6

Please sign in to comment.