From 628874a7b150d6f156ea426e69554d5336e2766e Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Mon, 7 Jul 2014 14:13:10 +0700 Subject: [PATCH] Initial commit --- README.md | 3 + nginx.conf | 604 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 607 insertions(+) create mode 100644 README.md create mode 100755 nginx.conf diff --git a/README.md b/README.md new file mode 100644 index 0000000..25f72de --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +## Paste Kitten + +A code snippet sharing application in a single Nginx config file. diff --git a/nginx.conf b/nginx.conf new file mode 100755 index 0000000..5a4d83c --- /dev/null +++ b/nginx.conf @@ -0,0 +1,604 @@ +# Paste Kitten +# A code snippet sharing application in a single Nginx config file. +# http://pastekitten.com/ + +# Source code is available on GitHub: +# https://github.com/localhots/pastekitten + +# Copyright (C) 2014 Gregory Eremin + +# 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. + +# upstream database { + # Set up database here + # postgres_server localhost:5432 dbname=pastekitten user=paste password=kitteh; + # postgres_keepalive max=80 mode=single overflow=ignore; +# } + +geo $dollar { + default '$'; +} + +server { + listen 80; + + # Change to your domain name + server_name pastekitten.dev; + + # Change this variable to your app's directory + set $root /Users/chez/Code/pastekitten; + + root $root; + access_log /Users/chez/Code/pastekitten/log/nginx.access.log; + error_log /Users/chez/Code/pastekitten/log/nginx.error.log debug; + + default_type text/html; + + location = / { + content_by_lua ' + ngx.say({ + ngx.var.header_html, + ngx.var.form_html, + ngx.var.footer_html + }) + '; + } + + location ^~ /paste { + content_by_lua ' + -- We wont need that function later + -- Its here for snippet purpose + function query(q) + local res = ngx.location.capture("/query", {args = {q = q}}) + local body = json.decode(res.body) + if res.status == 200 then + return true, body + else + return false, body + end + end + + -- Paste code goes here + + ngx.say("pasted!") + '; + } + + # Match /UUID4 URLs + # Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx + # Where: + # x - [0-9a-f] + # y - [89ab] + # Example: f47ac10b-58cc-4372-a567-0e02b2c3d479 + location ~* '^\/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab]{1}[0-9a-f]{3}-[0-9a-f]{12}$' { + content_by_lua ' + ngx.say("

show

") + '; + } + + # This is just sick, right? + # Internal endpoint for querying database + # Example: /query?q=select+*+from+table_name; + # location = /query { + # internal; + + # default_type application/json; + # rds_json on; + + # set_by_lua $query_sql 'return ngx.unescape_uri(ngx.var.arg_q)'; + # postgres_pass database; + # postgres_query $query_sql; + # } + + location = /source { + default_type text/plain; + alias /nginx.conf; + } + + location = /static/app.js { + default_type application/javascript; + content_by_lua 'ngx.say(ngx.var.app_js)'; + } + + location = /static/app.css { + default_type text/css; + content_by_lua 'ngx.say(ngx.var.app_css)'; + } + + location = /static/dropdown.css { + default_type text/css; + content_by_lua 'ngx.say(ngx.var.dropdown_css)'; + } + + location = /static/highlight.css { + default_type text/css; + content_by_lua ' + ngx.say( + ngx.var.highlight_pt1_css, + ngx.var.highlight_pt2_css + ) + '; + } + + set $header_html ' + + + + Paste Kitten + + + + + + + +
Save + +
+ Syntax + +
+
+ '; + + set $app_js ' + ${dollar}(function() { + "use strict"; + + var ${dollar}form = ${dollar}("form"), + ${dollar}contents = ${dollar}form.find("textarea"), + ${dollar}_button = ${dollar}form.find("input[type="submit"]"), + ${dollar}button = ${dollar}form.find("a[role="submit"]"), + ${dollar}syntax_selector = ${dollar}("#syntax-selector"); + + ${dollar}_button.hide(); + ${dollar}button.show(); + ${dollar}contents.focus(); + + ${dollar}button.on("click", function(e) { + if (${dollar}(this).hasClass("disabled")) { + return false; + } + + ${dollar}(this).addClass("disabled"); + ${dollar}syntax_selector.addClass("disabled"); + ${dollar}form.submit(); + + return false; + }); + + var ${dollar}input = ${dollar}("#syntax-input"), + ${dollar}textarea = ${dollar}("textarea"), + ${dollar}dropdown = ${dollar}("#syntax-selector"), + ${dollar}options = ${dollar}dropdown.find("ul.dropdown > li"), + ${dollar}placeholder = ${dollar}dropdown.children("span"), + prefix = ${dollar}placeholder.text(); + + ${dollar}dropdown.on("click", function() { + if (${dollar}(this).hasClass("disabled")) { + return false; + } + + ${dollar}dropdown.toggleClass("active"); + return false; + }); + + ${dollar}options.on("click", function() { + var ${dollar}el = ${dollar}(this); + + ${dollar}el.siblings().removeClass("selected"); + ${dollar}el.addClass("selected"); + ${dollar}placeholder.text(prefix + ": " + (${dollar}el.text())); + ${dollar}input.val(${dollar}el.data("value")); + ${dollar}("textarea").focus(); + + return false; + }); + + ${dollar}options.filter(".selected").click(); + ${dollar}dropdown.removeClass("active"); + + ${dollar}(document).on("click", function(e) { + ${dollar}(".wrapper-dropdown").removeClass("active"); + }); + }); + '; + + set $kitteh 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFcAAABGBAMAAABLbBVhAAAAJ1BMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADdEvm1AAAADXRSTlMAA2k9UJd/rScUwM3mzv8eMwAAA7JJREFUeNrFls1vE1cUxc/N+Ht1nig0kC7cBLsQdTFEpZGiLoY0b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MFGmm72JlyMVWgZI+0pwo/S4wiiXB93eqw22YN49b44MuzOI3QLo1PuwQnPb9YYbfl6sLQMalWI9F9AYwa6VcdRVLovitTfybFESsBpB6Ki/CUnIL755fjgY2i5eam5/Jy/yLJl5QikL8D/oHSN6ihuc8lhkAAAAASUVORK5CYII='; + + set $app_css ' + * + { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + } + body, input, select + { + font-family: Helvetica, Arial, sans-serif; + font-size: 1em; + } + textarea, pre + { + font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif; + font-size: 1em; + } + html, body, form + { + height: 100%; + } + body + { + padding: 3em; + + background-color: #fcfcfc; + } + h1 + { + font-size: 1em; + font-weight: 200; + line-height: 1em; + + position: absolute; + top: 1em; + left: 3em; + + margin: 0; + padding: 0; + + text-transform: uppercase; + + color: #ccc; + } + h1:before + { + display: block; + float: right; + + width: 43px; + height: 35px; + margin: -10px 0 0 5px; + + content: ""; + + opacity: .5; + background: url($kitteh); + background-repeat: no-repeat; + background-position: top left; + background-size: 43px 35px; + } + .linenos + { + padding-right: .5em; + + color: #ccc; + border-right: #eee 1px solid; + } + .code + { + padding-left: .5em; + } + .container + { + width: 100%; + height: 100%; + } + textarea, input + { + outline: none; + } + .btn + { + font-size: 1em; + + padding: .5em .8em; + + cursor: default; + text-decoration: none; + + color: #666; + color: #fff; + border: none; + border-radius: 2px; + outline: none; + background-color: rgb(0, 251, 94); + } + .btn:active + { + border-bottom-width: 1px; + box-shadow: 0 .1em .2em .1em #eee inset; + } + .btn.disabled + { + cursor: not-allowed; + + background: #f0f0f0; + } + textarea + { + line-height: 120%; + + width: 100%; + height: 100%; + padding: .5em; + + resize: none; + + border: #ddd 1px solid; + border-radius: 5px; + background-color: #fff; + } + #syntax-selector + { + float: right; + + width: 13em; + margin: .4em; + } + form input[type="submit"], form a[role="submit"] + { + font-weight: 600; + + float: right; + + width: 5em; + margin: .4em 0; + + text-align: center; + } + form a[role="submit"] + { + display: none; + } + '; + + set $dropdown_css ' + .wrapper-dropdown + { + position: relative; + } + .wrapper-dropdown:after + { + position: absolute; + top: 50%; + right: 16px; + + width: 0; + height: 0; + margin-top: -6px; + + content: ""; + + border-width: 6px 0 6px 6px; + border-style: solid; + border-color: transparent #888; + } + .wrapper-dropdown .dropdown + { + font-weight: normal; + + position: absolute; + right: 0; + bottom: 2em; + left: 0; + + overflow-x: ellipsis; + overflow-y: auto; + + height: 20em; + padding: 0; + + list-style: none; + + pointer-events: none; + + opacity: 0; + border: #ddd 1px solid; + border-radius: 5px; + background: #fafafa; + } + .wrapper-dropdown .dropdown li + { + display: block; + overflow: hidden; + + padding: 10px 20px; + + white-space: nowrap; + text-decoration: none; + text-overflow: ellipsis; + + color: #9e9e9e; + } + .wrapper-dropdown .dropdown li:hover + { + cursor: pointer; + + color: #fff; + background: #ccc; + text-shadow: none; + } + .wrapper-dropdown .dropdown li.selected + { + color: #666; + background: #eee; + } + .wrapper-dropdown.active + { + background: #fafafa; + } + .wrapper-dropdown.active .dropdown + { + pointer-events: auto; + + opacity: 1; + } + .wrapper-dropdown.active:after + { + margin-top: -3px; + + border-width: 0 6px 6px 6px; + border-color: #aaa transparent; + } + /* No CSS3 support */ + .no-opacity .wrapper-dropdown .dropdown, + .no-pointerevents .wrapper-dropdown .dropdown + { + display: none; + + pointer-events: auto; + + opacity: 1; + } + .no-opacity .wrapper-dropdown.active .dropdown, + .no-pointerevents .wrapper-dropdown.active .dropdown + { + display: block; + } + '; + + set $highlight_pt1_css ' + /* .highlight { background-color: #ffffcc } */ + .highlight .c { color: #586E75 } /* Comment */ + .highlight .err { color: #538181 } /* Error */ + .highlight .g { color: #538181 } /* Generic */ + .highlight .k { color: #859900 } /* Keyword */ + .highlight .l { color: #538181 } /* Literal */ + .highlight .n { color: #538181 } /* Name */ + .highlight .o { color: #859900 } /* Operator */ + .highlight .x { color: #CB4B16 } /* Other */ + .highlight .p { color: #538181 } /* Punctuation */ + .highlight .cm { color: #586E75 } /* Comment.Multiline */ + .highlight .cp { color: #859900 } /* Comment.Preproc */ + .highlight .c1 { color: #586E75 } /* Comment.Single */ + .highlight .cs { color: #859900 } /* Comment.Special */ + .highlight .gd { color: #2AA198 } /* Generic.Deleted */ + .highlight .ge { color: #538181; font-style: italic } /* Generic.Emph */ + .highlight .gr { color: #DC322F } /* Generic.Error */ + .highlight .gh { color: #CB4B16 } /* Generic.Heading */ + .highlight .gi { color: #859900 } /* Generic.Inserted */ + .highlight .go { color: #538181 } /* Generic.Output */ + .highlight .gp { color: #538181 } /* Generic.Prompt */ + .highlight .gs { color: #538181; font-weight: bold } /* Generic.Strong */ + .highlight .gu { color: #CB4B16 } /* Generic.Subheading */ + .highlight .gt { color: #538181 } /* Generic.Traceback */ + .highlight .kc { color: #CB4B16 } /* Keyword.Constant */ + .highlight .kd { color: #268BD2 } /* Keyword.Declaration */ + .highlight .kn { color: #859900 } /* Keyword.Namespace */ + .highlight .kp { color: #859900 } /* Keyword.Pseudo */ + .highlight .kr { color: #268BD2 } /* Keyword.Reserved */ + .highlight .kt { color: #DC322F } /* Keyword.Type */ + .highlight .ld { color: #538181 } /* Literal.Date */ + .highlight .m { color: #2AA198 } /* Literal.Number */ + .highlight .s { color: #2AA198 } /* Literal.String */ + .highlight .na { color: #538181 } /* Name.Attribute */ + '; + set $highlight_pt2_css ' + .highlight .nb { color: #B58900 } /* Name.Builtin */ + .highlight .nc { color: #268BD2 } /* Name.Class */ + .highlight .no { color: #CB4B16 } /* Name.Constant */ + .highlight .nd { color: #268BD2 } /* Name.Decorator */ + .highlight .ni { color: #CB4B16 } /* Name.Entity */ + .highlight .ne { color: #CB4B16 } /* Name.Exception */ + .highlight .nf { color: #268BD2 } /* Name.Function */ + .highlight .nl { color: #538181 } /* Name.Label */ + .highlight .nn { color: #538181 } /* Name.Namespace */ + .highlight .nx { color: #538181 } /* Name.Other */ + .highlight .py { color: #538181 } /* Name.Property */ + .highlight .nt { color: #268BD2 } /* Name.Tag */ + .highlight .nv { color: #268BD2 } /* Name.Variable */ + .highlight .ow { color: #859900 } /* Operator.Word */ + .highlight .w { color: #538181 } /* Text.Whitespace */ + .highlight .mf { color: #2AA198 } /* Literal.Number.Float */ + .highlight .mh { color: #2AA198 } /* Literal.Number.Hex */ + .highlight .mi { color: #2AA198 } /* Literal.Number.Integer */ + .highlight .mo { color: #2AA198 } /* Literal.Number.Oct */ + .highlight .sb { color: #586E75 } /* Literal.String.Backtick */ + .highlight .sc { color: #2AA198 } /* Literal.String.Char */ + .highlight .sd { color: #538181 } /* Literal.String.Doc */ + .highlight .s2 { color: #2AA198 } /* Literal.String.Double */ + .highlight .se { color: #CB4B16 } /* Literal.String.Escape */ + .highlight .sh { color: #538181 } /* Literal.String.Heredoc */ + .highlight .si { color: #2AA198 } /* Literal.String.Interpol */ + .highlight .sx { color: #2AA198 } /* Literal.String.Other */ + .highlight .sr { color: #DC322F } /* Literal.String.Regex */ + .highlight .s1 { color: #2AA198 } /* Literal.String.Single */ + .highlight .ss { color: #2AA198 } /* Literal.String.Symbol */ + .highlight .bp { color: #268BD2 } /* Name.Builtin.Pseudo */ + .highlight .vc { color: #268BD2 } /* Name.Variable.Class */ + .highlight .vg { color: #268BD2 } /* Name.Variable.Global */ + .highlight .vi { color: #268BD2 } /* Name.Variable.Instance */ + .highlight .il { color: #2AA198 } /* Literal.Number.Integer.Long */ + '; +}