<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by duffn on Medium]]></title>
        <description><![CDATA[Stories by duffn on Medium]]></description>
        <link>https://medium.com/@duffn?source=rss-30f85935e89d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*v0jHApjmxU-6FCpnCvA-zQ.png</url>
            <title>Stories by duffn on Medium</title>
            <link>https://medium.com/@duffn?source=rss-30f85935e89d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 11:45:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@duffn/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[You Are Great]]></title>
            <link>https://duffn.medium.com/you-are-great-fa9158d78fc9?source=rss-30f85935e89d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa9158d78fc9</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[mental-health]]></category>
            <dc:creator><![CDATA[duffn]]></dc:creator>
            <pubDate>Fri, 09 Aug 2019 12:47:14 GMT</pubDate>
            <atom:updated>2019-08-09T12:48:36.273Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cqeFouy-7qo8ERcrYGMCww.jpeg" /></figure><p>Though it may not always feel like it, it’s important to remember that you are special, you are wanted, you are great.</p><p>I made a thing to try to help make a sad friend feel better. Maybe it will bring a smile to your face, too.</p><p><a href="https://youaregreat.fyi/">https://youaregreat.fyi</a></p><pre>$ curl <a href="https://youaregreat.fyi/api/">https://youaregreat.fyi/api/</a></pre><pre>{&quot;message&quot;:&quot;You are great. 🌟&quot;}</pre><pre>$ curl <a href="https://youaregreat.fyi/api/?name=Julie">https://youaregreat.fyi/api/?name=Julie</a></pre><pre>{&quot;message&quot;:&quot;Hello Julie. You are appreciated.&quot;}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa9158d78fc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyzing Cloudflare Logs with AWS Athena]]></title>
            <link>https://duffn.medium.com/analyzing-cloudflare-logs-with-aws-athena-19c1399c91e3?source=rss-30f85935e89d------2</link>
            <guid isPermaLink="false">https://medium.com/p/19c1399c91e3</guid>
            <category><![CDATA[athena]]></category>
            <category><![CDATA[cloudflare]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[logging]]></category>
            <dc:creator><![CDATA[duffn]]></dc:creator>
            <pubDate>Sat, 03 Aug 2019 00:04:25 GMT</pubDate>
            <atom:updated>2019-08-09T13:51:15.874Z</atom:updated>
            <content:encoded><![CDATA[<p>As with many features with Cloudflare, you can enable their <a href="https://developers.cloudflare.com/logs/logpush/">Logpush service</a> with the click of a button. Logpush sends your HTTP request logs to your cloud storage provider every 5 minutes.</p><p>If you are using AWS S3 for your storage, you can then utilize <a href="https://aws.amazon.com/athena/">Athena</a> to analyze your logs.</p><blockquote><em>Athena is an interactive query service that makes it easy to analyze data in Amazon S3 using standard SQL.</em></blockquote><p>So with a little setup and some simple SQL, you can analyze your Cloudflare logs.</p><h3>Table DDL</h3><p>In order to being querying, however, you need to <a href="https://docs.aws.amazon.com/athena/latest/ug/create-table.html">create an external table</a> in Athena that matches the format of your Cloudflare logs, which are JSON with a newline delineating each record.</p><p>Luckily, this is pretty easy to setup in Athena. Here is the DDL for all of the fields currently included in Cloudflare Logpush.</p><p><em>Note:</em> You can customize the <a href="https://developers.cloudflare.com/logs/logpull-api/requesting-logs/#fields">fields</a> that Logpush includes, so if you have, your list of fields may not match the below exactly.</p><pre>CREATE EXTERNAL TABLE cloudflare_logs (<br>    CacheCacheStatus string,<br>    CacheResponseBytes int,<br>    CacheResponseStatus int,<br>    CacheTieredFill boolean,<br>    ClientASN int,<br>    ClientCountry string,<br>    ClientDeviceType string,<br>    ClientIP string,<br>    ClientIPClass string,<br>    ClientRequestBytes int,<br>    ClientRequestHost string,<br>    ClientRequestMethod string,<br>    ClientRequestPath string,<br>    ClientRequestProtocol string,<br>    ClientRequestReferer string,<br>    ClientRequestURI string,<br>    ClientRequestUserAgent string,<br>    ClientSSLCipher string,<br>    ClientSSLProtocol string,<br>    ClientSrcPort int,<br>    EdgeColoID int,<br>    EdgeEndTimestamp string,<br>    EdgePathingOp string,<br>    EdgePathingSrc string,<br>    EdgePathingStatus string,<br>    EdgeRateLimitAction string,<br>    EdgeRateLimitID int,<br>    EdgeRequestHost string,<br>    EdgeResponseBytes int,<br>    EdgeResponseCompressionRatio double,<br>    EdgeResponseContentType string,<br>    EdgeResponseStatus int,<br>    EdgeServerIP string,<br>    EdgeStartTimestamp string,<br>    FirewallMatchesActions ARRAY &lt; string &gt;,<br>    FirewallMatchesSources ARRAY &lt; string &gt;,<br>    FirewallMatchesRuleIDs ARRAY &lt; string &gt;,<br>    OriginIP string,<br>    OriginResponseBytes int,<br>    OriginResponseHTTPExpires string,<br>    OriginResponseHTTPLastModified string,<br>    OriginResponseStatus int,<br>    OriginResponseTime bigint,<br>    OriginSSLProtocol string,<br>    ParentRayID string,<br>    RayID string,<br>    SecurityLevel string,<br>    WAFAction string,<br>    WAFFlags string,<br>    WAFMatchedVar string,<br>    WAFProfile string,<br>    WAFRuleID string,<br>    WAFRuleMessage string,<br>    WorkerCPUTime int,<br>    WorkerStatus string,<br>    WorkerSubrequest boolean,<br>    WorkerSubrequestCount int,<br>    ZoneID bigint)<br>ROW FORMAT SERDE &#39;org.openx.data.jsonserde.JsonSerDe&#39; LOCATION &#39;s3://my-cloudflare-logs/&#39;</pre><p>Of course, change s3://my-cloudflare-logs/ to the name of your bucket that you used when setting up Logpush.</p><h3>Querying</h3><p>An now that we have a table created in Athena, we can analyze our logs in a myriad of ways.</p><p>How about checking to see how many requests you’ve received by the request protocol?</p><pre>SELECT count(*) as requests,<br>         c.clientrequestprotocol<br>FROM &quot;cloudflare_logs&quot;.&quot;cloudflare_logs&quot; c<br>GROUP BY  c.clientrequestprotocol<br>ORDER BY  count(*) DESC limit 10;</pre><pre>        requests    clientrequestprotocol<br>1	15063737    HTTP/2<br>2	6842951     HTTP/1.1<br>3	4342	    HTTP/1.0</pre><p>Or maybe for reasons unknown, you want to see the average client request size in bytes for today, grouped by the Cloudflare edge colo ID.</p><pre>SELECT avg(clientrequestbytes),<br>         edgecoloid<br>FROM &quot;cloudflare_logs&quot;.&quot;cloudflare_logs&quot;<br>-- Assuming you are using the default date format with Logpush<br>WHERE date_trunc(&#39;day&#39;, from_iso8601_timestamp(edgestarttimestamp)) = current_date<br>GROUP BY  edgecoloid<br>ORDER BY  avg(clientrequestbytes) ASC;</pre><p>As you can imagine, the ways that you can slice and dice your Cloudflare HTTP logs is nearly limitless. Enjoy diving deep on your Cloudflare logs!</p><p><em>Originally published at </em><a href="https://nicholasduffy.com/posts/analyzing-cloudflare-logs-with-aws-athena/"><em>https://nicholasduffy.com</em></a><em> on August 3, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19c1399c91e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Minikube with Local Docker Images]]></title>
            <link>https://duffn.medium.com/using-minikube-with-local-docker-images-1a8289394f6c?source=rss-30f85935e89d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a8289394f6c</guid>
            <category><![CDATA[minikube]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[duffn]]></dc:creator>
            <pubDate>Sat, 29 Sep 2018 14:03:22 GMT</pubDate>
            <atom:updated>2021-02-14T22:46:33.656Z</atom:updated>
            <content:encoded><![CDATA[<p>When developing locally with <a href="https://kubernetes.io/docs/setup/minikube/">Minikube</a>, you may want to use locally built Docker images instead of images hosted in a registry. Why push images up to Google’s GCR or AWS ECR if you’re only testing locally? Thankfully, this is simple with only a few steps.</p><ul><li>With Minikube running, eval the docker-env to configure your shell to get started.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2db28bf17055760b1497853dac8335d8/href">https://medium.com/media/2db28bf17055760b1497853dac8335d8/href</a></iframe><ul><li>Build your image.</li><li>In the containers specification of your deployment, use the locally built image and specify the <a href="https://kubernetes.io/docs/concepts/containers/images/#pre-pulling-images">imagePullPolicy</a>. Setting this policy to IfNotPresent tells Kubernetes to use a local image preferentially.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/207b839c93595a4ff93ecd52e3530186/href">https://medium.com/media/207b839c93595a4ff93ecd52e3530186/href</a></iframe><ul><li>Apply the deployment and that’s it! You have a locally built image running in Minikube on your machine.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a8289394f6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Static Websites with AWS S3 and Cloudflare]]></title>
            <link>https://duffn.medium.com/static-websites-with-aws-s3-and-cloudflare-2cb6397108c?source=rss-30f85935e89d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cb6397108c</guid>
            <category><![CDATA[cloudflare]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[website]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[duffn]]></dc:creator>
            <pubDate>Sat, 29 Sep 2018 13:59:33 GMT</pubDate>
            <atom:updated>2018-09-29T13:59:33.959Z</atom:updated>
            <content:encoded><![CDATA[<p>Amazon Web Service’s <a href="https://aws.amazon.com/s3/">S3</a> is an excellent place to deploy a static website. If <a href="https://www.cloudflare.com/">Cloudflare</a> is your DNS provider, however, there are a few tricks that you need to be aware of when setting up your static site.</p><p>We’re going to talk about how to get started with your static site on S3 and your DNS in Cloudflare.</p><ul><li><a href="https://gist.github.com/e683dd8aec073b09860367380815a906#AWS">AWS</a></li><li><a href="https://gist.github.com/e683dd8aec073b09860367380815a906#s3-bucket-configuration">S3 Bucket</a></li><li><a href="https://gist.github.com/e683dd8aec073b09860367380815a906#cloudflare-distribution">Cloudfront Distribution</a></li><li><a href="https://gist.github.com/e683dd8aec073b09860367380815a906#cloudflare">Cloudflare</a></li></ul><h3>AWS</h3><p>First, of course, we need a static site deployed to S3. The <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html">AWS documentation</a> does a good job at explaining how to setup a site, but we’ll briefly run through the steps here as well.</p><h3>S3 Bucket Configuration</h3><p>One of the first things that you’ll see in the AWS documentation linked above is that your bucket name must match the name of the website you are hosting. That’s true in most cases, but since we’re going to be using Cloudflare DNS, that’s not true in our case.</p><p>Oh, and we don’t even need to tell AWS that we’re going to be using this bucket to host our site. I’ll show you why shortly.</p><ul><li>Head to the <a href="https://s3.console.aws.amazon.com/s3/home">S3 home page</a> and create a bucket named whatever you like.</li><li>Give your bucket this policy, changing example.com to the name of the bucket you just created.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc826de97621df0662c78d5e9a231de3/href">https://medium.com/media/cc826de97621df0662c78d5e9a231de3/href</a></iframe><p><strong>NOTE</strong>: <em>This makes items in your bucket available to the public. Do not put things in this bucket that you do not want everybody in the world seeing.</em></p><ul><li>You can upload whatever HTML, CSS and JS you want to serve on your site, but for now just upload a simple index.html file for testing.</li></ul><h3>Cloudfront Distribution</h3><p>Now, we’re going to create a <a href="https://aws.amazon.com/cloudfront/">Cloudfront</a> distribution in AWS. While not strictly necessary for a static website on AWS, it is necessary to get Cloudflare’s SSL to work with our site.</p><ul><li>On the <a href="https://console.aws.amazon.com/cloudfront/home">Cloudfront</a> service page and click Create Distribution.</li><li>Click Get Started under the Web section on the next page.</li><li>In the Origin Domain Name input, select the bucket that you created above.</li><li>We’re going to select Redirect HTTP to HTTPS for the Viewer Protocol Policy option.</li><li>There are only two other things that we need to change now. Here are those tricky bits that you may not have known about!</li><li>In the Alternate Domain Names (CNAMEs) input, type the domain name that we&#39;re going to use for our site. This your domain that you will or already have setup in Cloudflare.</li><li>In Default Root Object, enter index.html, the file that we uploaded the our bucket.</li><li>That’s all we need to do to setup Cloudfront. Hang tight though, as this can sometimes take awhile to become active.</li></ul><h3>Cloudflare</h3><p>We’re in the final stretch now. We only have to setup Cloudflare to point to our Cloudfront distribution. From here on out, I’m going to assume that you already have an account and have setup your domain in Cloudflare.</p><h3>DNS</h3><ul><li>On the DNS tab of your <a href="https://dash.cloudflare.com/">Cloudflare dashboard</a>, we’re going to add two CNAME records.</li><li>Add one CNAME record with the Name of your domain, example.com, and the Domain Name of your Cloudfront distribution, d1234gflgylt.cloudfront.net. Make sure not to include https:// with your Cloudfront distribution.</li><li>Add another record with the Name of www and again the Domain Name of your Cloudfront distribution. We want to make sure that we send both www.example.com and example.com to our static site.</li><li>Make sure to leave the little Cloudflare cloud checked and orange.</li></ul><p>And that’s it! Wait a few minutes (most likely seconds), and you’ll see your static site served from S3, through a Cloudfront distribution and finally to Cloudflare under your custom domain.</p><p><em>Originally published at </em><a href="https://nicholasduffy.com/posts/static-websites-s3-cloudflare/"><em>nicholasduffy.com</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cb6397108c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing GReleaser]]></title>
            <link>https://duffn.medium.com/introduction-greleaser-922f5219ebaf?source=rss-30f85935e89d------2</link>
            <guid isPermaLink="false">https://medium.com/p/922f5219ebaf</guid>
            <category><![CDATA[jira]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[duffn]]></dc:creator>
            <pubDate>Sun, 19 Aug 2018 15:07:39 GMT</pubDate>
            <atom:updated>2018-08-19T15:08:43.297Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you use Jira? Do you use GitHub? Do you create versions in Jira and also releases in GitHub? Are you tired of manually tagging commits in GitHub and copying release notes from Jira?</p><p>Then GReleaser is for you!</p><p>GReleaser is a command line tool that allows you to automatically create releases in GitHub using Jira release notes and names.</p><p>To create a release in GitHub from a Jira version, it can be as simple as passing the Jira project, version and the name of your GitHub repo.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04035ab6528252dcf0c64f80360b6b7c/href">https://medium.com/media/04035ab6528252dcf0c64f80360b6b7c/href</a></iframe><p>There are many more options that can be passed in, including the commit to tag, tag name, release name and more.</p><p>See the full details at <a href="https://github.com/duffn/greleaser">https://github.com/duffn/greleaser</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=922f5219ebaf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Supervisor reread and update]]></title>
            <link>https://duffn.medium.com/supervisor-reread-and-update-283207801e84?source=rss-30f85935e89d------2</link>
            <guid isPermaLink="false">https://medium.com/p/283207801e84</guid>
            <dc:creator><![CDATA[duffn]]></dc:creator>
            <pubDate>Sat, 30 Jul 2016 13:05:20 GMT</pubDate>
            <atom:updated>2016-07-30T13:05:20.602Z</atom:updated>
            <content:encoded><![CDATA[<p>I needed to add some options to <a href="http://gunicorn.org/">gunicorn</a> running under <a href="http://supervisord.org/">supervisor</a> the other day. I ran gunicorn from the command line with the new argurments — no problem. I added the arguments to the command in supervisor, restarted with supervisorctl — problem.</p><p>Supervisor wasn’t picking up the new arguments. I restarted again. Nothing. I tried the command arguments inline. I tried a gunicorn <a href="http://docs.gunicorn.org/en/stable/settings.html#config-file">conf</a> file. I tried a shell script with the commands. All nothing.</p><p>After spending an embarrassing amount of time trying to figure out what was wrong, I finally remembered! You need to reread and update the supervisor conf file after making changes. Simply restarting via supervisorctl is not enough.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44c0ef12a65909ad39b8adf322fb8d90/href">https://medium.com/media/44c0ef12a65909ad39b8adf322fb8d90/href</a></iframe><p>So don’t forget. Reread and update after changing a supervisor configuration, otherwise it won’t get picked up.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=283207801e84" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a date dimension table in PostgreSQL]]></title>
            <link>https://duffn.medium.com/creating-a-date-dimension-table-in-postgresql-af3f8e2941ac?source=rss-30f85935e89d------2</link>
            <guid isPermaLink="false">https://medium.com/p/af3f8e2941ac</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[duffn]]></dc:creator>
            <pubDate>Fri, 22 Apr 2016 15:27:32 GMT</pubDate>
            <atom:updated>2016-04-22T15:30:38.564Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever read any of <a href="http://www.kimballgroup.com/">Ralph Kimball’s data warehouse books</a> or have any experience with modeling data in the Kimball style, you know that a date dimension is a key part of any star schema.</p><p>You probably found resources for creating Oracle, SQL Server or MySQL but may have had difficulty finding SQL to create a date dimension table for PostgreSQL.</p><p>Here’s a bit of code adapted from the <a href="https://wiki.postgresql.org/wiki/Date_and_Time_dimensions">PostgreSQL wiki</a> that I like for creating the ever necessary date dimension in PostgreSQL.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28842dd086a94c18e4421b28f444e2a9/href">https://medium.com/media/28842dd086a94c18e4421b28f444e2a9/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af3f8e2941ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with LoopBack and SQL Server]]></title>
            <link>https://duffn.medium.com/getting-started-with-loopback-and-sql-server-653aeb404cbb?source=rss-30f85935e89d------2</link>
            <guid isPermaLink="false">https://medium.com/p/653aeb404cbb</guid>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[loopback]]></category>
            <dc:creator><![CDATA[duffn]]></dc:creator>
            <pubDate>Mon, 23 Mar 2015 13:51:50 GMT</pubDate>
            <atom:updated>2015-11-24T21:47:40.335Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, we’ll talk about getting started with LoopBack and SQL Server. We’ll create an API using an existing SQL Server table as the backend. Let’s jump right in.</p><h3>Prerequisites</h3><ul><li>You have Node.js installed</li><li>You have some version of SQL Server installed</li></ul><h3>SQL Server</h3><p>You know SQL Server.</p><blockquote><em>SQL Server is Microsofts RDMS offering for OLTP, data warehousing, business intelligence and analytics.</em></blockquote><h4>The data</h4><p>We’re going to be using an existing SQL Server table in our database. This should be a very common scenario when working with LoopBack and SQL Server as you are likely not creating your tables in SQL Server specifically while creating your LoopBack application.</p><p>We’ll use the excellent <a href="http://www.generatedata.com/">generatedata.com</a> site to seed our table with 100 rows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4924820f8dea05341a4c7f779665d19/href">https://medium.com/media/e4924820f8dea05341a4c7f779665d19/href</a></iframe><p>Alright, now that we have our already existing table example setup, let’s move on to LoopBack.</p><h3>LoopBack</h3><blockquote><em>LoopBack is a highly-extensible, open-source Node.js framework</em></blockquote><p><a href="http://loopback.io/">LoopBack</a> allows you to do many things like:</p><ul><li>Quickly create dynamic end-to-end REST APIs.</li><li>Connect devices and browsers to data and services.</li><li>Use Android, iOS, and AngularJS SDKs to easily create client apps.</li><li>Add-on components for push, file management, 3rd-party login, and geolocation.</li><li>Use StrongLoop Arc to visually edit, deploy, and monitor LoopBack apps.</li><li>LoopBack API gateway acts an intermediary between API consumers (clients) and API providers to externalize, secure, and manage APIs.</li><li>Runs on-premises or in the cloud</li></ul><p>We are going to use LoopBack to:</p><ul><li>Connect to our SQL Server database.</li><li>Discover the schema of our already existing table and create a LoopBack model based upon the schema.</li><li>Create a REST based API using this model.</li></ul><h4>Install LoopBack</h4><p>Before we do any of that, let’s walk through the very simple steps needed to install LoopBack.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/477f919048e4126985acf1d94e0111f0/href">https://medium.com/media/477f919048e4126985acf1d94e0111f0/href</a></iframe><p>Well that was easy! Now let’s scaffold our new LoopBack API application.</p><p>Run the LoopBack application generator and answer a few quick questions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbc8a043483037ae618f0232e738bc61/href">https://medium.com/media/bbc8a043483037ae618f0232e738bc61/href</a></iframe><p>After the generator runs and npm installs all the necessary packages, you’ll receive a message like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82d3b4ed986c02d4d4f671a553659273/href">https://medium.com/media/82d3b4ed986c02d4d4f671a553659273/href</a></iframe><p>The only thing left for us right now is to install a database connector for our application so that we can connect to SQL Server. Loopback offers a number of different connects, but we want loopback-connector-mssql.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4813154eb068b644fd5140eb34578078/href">https://medium.com/media/4813154eb068b644fd5140eb34578078/href</a></iframe><h4>Connect to SQL Server</h4><p>Now we need to point our LoopBack application to our SQL Server. In your loopback-sqlserver-example directory, open up the server/datasources.js file. Initially there is only a listing for the in-memory database, but we want to add a reference to our SQL Server.</p><p>Edit the file to look like this, of course, replacing with your SQL Server host, username and password.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e37f71f8fa23b474d80d34c16dd67071/href">https://medium.com/media/e37f71f8fa23b474d80d34c16dd67071/href</a></iframe><p>Now we’re ready to build our LoopBack model for our SQL Server table.</p><h4>LoopBack table model</h4><p>LoopBack uses JSON models to <a href="http://docs.strongloop.com/display/public/LB/SQL+Server+connector#SQLServerconnector-Definingmodels">define</a> tables in the application. While we could create the JSON by hand, we want to use our already existing table to automatically generate it for us. Thankfully LoopBack offers the discoverSchema method which will auto generate the JSON for us based upon our already existent SQL Server table.</p><p>Create a server/discover.js file and put in this code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/487a85225d04487599f69a0c6f39ff6b/href">https://medium.com/media/487a85225d04487599f69a0c6f39ff6b/href</a></iframe><p>First we get a reference to our app and then to the mySqlServer data source we created in the datasource.js file. Then we tell LoopBack to go get the schema of our table and output the JSON model to the console.</p><p>Run this script and you’ll get LoopBack’s JSON model representation of your table.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f9cdc9cae6a2b33a390a5da6c24b4d2/href">https://medium.com/media/2f9cdc9cae6a2b33a390a5da6c24b4d2/href</a></iframe><p>Cool! LoopBack just autogenerated a model of our contacts table based upon the already existing table.</p><p>Let’s get that model integrated into our app. We need to create two files to represent our contacts table in LoopBack.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b5c7cc3e48417e2a5f80ed917de9d08/href">https://medium.com/media/3b5c7cc3e48417e2a5f80ed917de9d08/href</a></iframe><p>The JSON file will hold our model definition and JavaScript file will export our model. There are more uses for the JavaScript file which we’ll get into in future posts.</p><p>First, copy the JSON we generated above into the contacts.json file.</p><p>Next, drop this simple code into the contacts.js file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1139bf9c2bc38c2b4fe0c403a77a9e1f/href">https://medium.com/media/1139bf9c2bc38c2b4fe0c403a77a9e1f/href</a></iframe><p>That’s it for creating our LoopBack model. Now we can tell LoopBack to use our model in the API.</p><h4>Create the API</h4><p>We need to tell LoopBack to use our newly created Contact model in the API. To do so, we open up server/model-config.json and add an entry for our model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/084ddd3bf3e691bdf7a54f9d640c4fab/href">https://medium.com/media/084ddd3bf3e691bdf7a54f9d640c4fab/href</a></iframe><p>model-config.json already has some definitions in it for the LoopBack base models. We’ll add our Contacts model at the end. Note that we set “public”: true to tell LoopBack to expose our model via the API.</p><h4>Run the API</h4><p>Now it’s time to fire up our API!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ddce9b5850cc18099f27a5d8535759f/href">https://medium.com/media/3ddce9b5850cc18099f27a5d8535759f/href</a></iframe><p>Browse to <a href="http://localhost:3000/explorer">http://localhost:3000/explorer</a> to see your API in action. Try to retrieve some data using the explorer and you can see that we have an working API!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*uXA7ekHNFwCm_CuU.png" /></figure><h3>Conclusion</h3><p>It doesn’t take much to get an API up and running with LoopBack, even if you need to connect to and discover and already existing table in SQL Server — or in any database for that matter!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=653aeb404cbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Jenkins CI with your Node.js LoopBack API and Bitbucket]]></title>
            <link>https://duffn.medium.com/setup-jenkins-ci-with-your-node-js-loopback-api-and-bitbucket-1a465c120043?source=rss-30f85935e89d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a465c120043</guid>
            <category><![CDATA[bitbucket]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[loopback]]></category>
            <dc:creator><![CDATA[duffn]]></dc:creator>
            <pubDate>Sun, 22 Mar 2015 22:04:49 GMT</pubDate>
            <atom:updated>2015-11-24T21:40:46.408Z</atom:updated>
            <content:encoded><![CDATA[<p>This tutorial will cover setting up your Nodes.js LoopBack API application with a private Bitbucket repository and Jenkins CI for your continuous integration needs. This is a relatively straightforward process, but there are a few points to which you need to pay attention. Let’s jump right in.</p><h3>Prerequisites</h3><ul><li>You have Node.js installed</li><li>You have git installed</li><li>You have a Bitbucket account</li></ul><h3>LoopBack</h3><blockquote><em>LoopBack is a highly-extensible, open-source Node.js framework</em></blockquote><p><a href="http://loopback.io/">LoopBack</a> allows you to do many things like:</p><ul><li>Quickly create dynamic end-to-end REST APIs.</li><li>Connect devices and browsers to data and services.</li><li>Use Android, iOS, and AngularJS SDKs to easily create client apps.</li><li>Add-on components for push, file management, 3rd-party login, and geolocation.</li><li>Use StrongLoop Arc to visually edit, deploy, and monitor LoopBack apps.</li><li>LoopBack API gateway acts an intermediary between API consumers (clients) and API providers to externalize, secure, and manage APIs.</li><li>Runs on-premises or in the cloud</li></ul><h4>Setup LoopBack</h4><p>Since this post is more about integrating LoopBack and Jenkins, we’re just going to use the <a href="https://github.com/strongloop/loopback-example-app">LoopBack example application</a>. Let’s get this up and running in a few quick lines.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2f92130f33b3bd41c016abee20ee940/href">https://medium.com/media/a2f92130f33b3bd41c016abee20ee940/href</a></iframe><p>Navigate to <a href="http://localhost:3000/explorer">http://localhost:3000/explorer</a>. You just created a full-fledged API with documentation and an API explorer in seconds!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zcJ41eVaRQKHB18g.png" /></figure><p>There’s much more to LoopBack than this, of course, but this will do for the purpose of the tutorial. Look for more <a href="http://www.mindlia.com/tag/loopback/">LoopBack related posts</a> to come. In the meantime, check out their <a href="http://docs.strongloop.com/display/SL/Installing+StrongLoop">documentation</a> for more information on all the amazing things you can do with LoopBack.</p><h4>Make a test</h4><p>Let’s make 1 nonsense test for the purposes of our example. We’ll be using the very popular <a href="http://mochajs.org/">Mocha</a> testing framework. First we need to install the mocha package.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/607d1d875ff42094419be089757328aa/href">https://medium.com/media/607d1d875ff42094419be089757328aa/href</a></iframe><p>Then we add our test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65893ef4f01545e22b998a88e8c225d4/href">https://medium.com/media/65893ef4f01545e22b998a88e8c225d4/href</a></iframe><p>Lastly, we make a slight change to the package.json scripts command to run out test. We don’t need jshint for right now and we installed mocha locally to our app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e087c06c9721e07926ff385ca1ddf79/href">https://medium.com/media/4e087c06c9721e07926ff385ca1ddf79/href</a></iframe><p>Let’s run our test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4c8c9637d8a14ecd2b51425dc4d64cf/href">https://medium.com/media/b4c8c9637d8a14ecd2b51425dc4d64cf/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*c_sS_AkXgsd53aHD.png" /></figure><p>Excellent, we have an API and a passing test! Let’s push this to our private Bitbucket repository, then we’ll get it working with Jenkins CI.</p><p>Create your Bitbucket repository and then push the first commit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/deba794fad9e2e98c2f7eb677c0b9a62/href">https://medium.com/media/deba794fad9e2e98c2f7eb677c0b9a62/href</a></iframe><p>Alright, we are ready to move on to Jenkins.</p><h3>Jenkins CI</h3><blockquote><em>Jenkins is an award-winning application that monitors executions of repeated jobs, such as building a software project or jobs run by cron.</em></blockquote><h4>Setup Jenkins CI</h4><p>We’re going to make setting up Jenkins CI version 1.602 easy and use the <a href="https://bitnami.com/">Bitnami</a> application. If you haven’t used Bitnami before, they describe themselves as a <em>library of popular server applications and development environments that can be installed with one click.</em> What that means for us is that we don’t have to go through the potential pain of installing an application like Jenkins ourselves. We can just download the already preconfigured VM and launch it in Virtualbox.</p><p><a href="https://bitnami.com/stack/jenkins/virtual-machine">Download</a> the Jenkins CI VM from Bitnami.</p><p><a href="https://wiki.bitnami.com/Virtual_Appliances_Quick_Start_Guide#Virtual_Box">Open up</a> the VM in Virtualbox.</p><p>When you launch the application for the first time, you’ll be given the default username and password as well as the IP address at which you can access Jenkins CI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*62AIUq5EsoGQ03X4.png" /></figure><p>Head to that IP address/jenkins to see your app: <a href="http://10.0.10.118/jenkins">http://10.0.10.118/jenkins</a></p><h4>Create a Jenkins CI job</h4><p>Let’s create our Jenkins CI job for our LoopBack application.</p><p>Login and then select <em>New Item</em> from the menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/0*e3sNKZl1haOoM_iT.png" /></figure><p>Choose <em>Freestyle Project</em>, enter the name of the project and click ok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WU7L4Cp-MQM9N6yR.png" /></figure><h4>Integrate Jenkins and Bitbucket</h4><p>Now we need to setup Jenkins so that it can access our private Bitbucket repository.</p><p><strong>Tricky part #1</strong></p><blockquote><em>The Jenkins application in Bitnami runs as the tomcat user.</em></blockquote><p>Despite the fact that this is laid out pretty clearly in the Bitnami documentation, don’t get tripped up by the fact that in Bitnami the Jenkins application runs as the tomcat user.</p><p>Take a minute to setup the tomcat user with an ssh key as described in the <a href="https://wiki.bitnami.com/Applications/BitNami_Jenkins#How_to_start_with_Git_and_Jenkins.3f">Bitnami documentation</a> for Jenkins.</p><p>Now that you have an ssh key for the tomcat user, <a href="https://confluence.atlassian.com/display/BITBUCKET/Add+an+SSH+key+to+an+account">add that key to Bitbucket</a> so that Jenkins can access the repository.</p><p>Alright, now that we setup Bitbucket properly and have our tomcat user ssh key ready, back to Jenkins to configure our job.</p><p>Select <em>Git</em> from the Source Code Management section and click Add next to Credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/0*DCfX2Jbr90tyeJAA.png" /></figure><p>Tell Jenkins to use the ssh key you created for the tomcat user above by selecting <em>SSH Username with private key</em> as the kind of credential, entering <em>tomcat</em> as the username and selecting <em>From the Jenkins master ~/.ssh</em> as the Private Key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kVX187wOhEiKl5ic.png" /></figure><p>Click add, select your credentials from the Credentials dropdown on the main configuration screen and enter git@bitbucket.org:myusername/loopback-example.git for the Repository URL.</p><h4>Build the project</h4><p>Now that we’re all set with Bitbucket, let’s tell Jenkins what to do with our project.</p><p>In the Build Triggers section, select <em>Poll SCM</em> and add */1 * * * *. Jenkins will ask you if you’re sure you want to check the repository every minute. Adjust as you see fit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cRCVABp6meJOrVvi.png" /></figure><p>Now we need to actually need to tell Jenkins what to do with our repository when it gets a hold of it. Select <em>Execute shell</em> from the Add Build Step dropdown in the Build section.</p><p>Tell Jenkins to install the necessary packages and run our test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/0*MW_AYxXXJ6RuqqV8.png" /></figure><blockquote>Note<em>: Don’t forget to install Node.js on the Jenkins server!</em></blockquote><p><strong>Tricky part #2</strong></p><blockquote><em>/usr/local/bin needs to be in Jenkins path or it won’t be able to find npm.</em></blockquote><p>You can set Jenkins environment variables directly in the application.</p><p>Go to Manage Jenkins-&gt;Configure System and add to the Global Properties-&gt;Environment Variables section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u-5AYAFFBs7fTMKe.png" /></figure><p>Now, you can either click <em>Build Now</em> in the project menu or wait one minute to have Jenkins poll your repository and build your application.</p><p>Soon enough, you’ll see some beautiful output in the Console Log window!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z52xrAGmXo7mJv_9.png" /></figure><h3>Conclusion</h3><p>There are a number of steps to get Jenkins setup to work with your private Bitbucket repository and a LoopBack application, but if you know about the tricky parts — which now you do — it shouldn’t take you too long.</p><p>After you do have it setup, however, Jenkins will build your app every time you push to Bitbucket!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a465c120043" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging LoopBack API requests to Keen.io]]></title>
            <link>https://duffn.medium.com/logging-loopback-api-requests-to-keen-io-9945b52f4243?source=rss-30f85935e89d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9945b52f4243</guid>
            <category><![CDATA[loopback]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[keen-io]]></category>
            <dc:creator><![CDATA[duffn]]></dc:creator>
            <pubDate>Sat, 14 Mar 2015 22:23:00 GMT</pubDate>
            <atom:updated>2015-11-24T15:59:38.553Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been experimenting with <a href="http://loopback.io/">LoopBack</a> recently, using it to prototype an API. It really is quite amazing how quickly you can get a full-fledged API up and running with LoopBack. Just follow the <a href="http://docs.strongloop.com/display/public/LB/Getting+started+with+LoopBack">getting started guide</a> and you’ll see what I mean.</p><p>After getting a pretty decent API up and running, I began testing a few different ways of logging API requests. I still haven’t quite settled on the way that I want to do this yet, but one issue that I did encounter was trying to get the response time of the call from <a href="https://github.com/expressjs/response-time">expressjs/response-time</a>.</p><p>Response-time is a great, little Node.js module that automatically adds an X-Response-Time header to your responses to indicate the time in milliseconds that the request took.</p><p>The issue that I was running into was that I could not figure out how to properly get to that header in the LoopBack afterRemote method that I was using to log requests. Thanks to an <a href="http://stackoverflow.com/questions/28917210/can-i-get-to-response-headers-in-loopback-afterremote-hook/29028330#29028330">SO</a> user, however, I was able to eventually get to what I wanted. The key was that the response wasn’t available when I was trying to log the query — I needed to use the res.on(‘finish’) event to get the response headers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a56600c583311c8b9618cd9a21f32ef9/href">https://medium.com/media/a56600c583311c8b9618cd9a21f32ef9/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9945b52f4243" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>