From c0bf17fdc4c6304785f4b95a48545f65bd772a20 Mon Sep 17 00:00:00 2001 From: Eduardo Trujillo <ed@chromabits.com> Date: Mon, 15 Feb 2016 22:41:18 -0500 Subject: [PATCH] Add support for IPv6 amound other things --- blog.cabal | 3 ++- robots.txt | 2 ++ server.hs | 13 ++++++++----- site.hs | 9 ++++++++- templates/default.html | 14 +++++++------- 5 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 robots.txt diff --git a/blog.cabal b/blog.cabal index 7dfe258..e1bf90c 100644 --- a/blog.cabal +++ b/blog.cabal @@ -38,4 +38,5 @@ executable server warp-tls == 3.*, wai == 3.*, wai-extra <= 3.0.14, - wai-app-static == 3.* + wai-app-static == 3.*, + streaming-commons == 0.1.* diff --git a/robots.txt b/robots.txt new file mode 100644 index 0000000..8ed215a --- /dev/null +++ b/robots.txt @@ -0,0 +1,2 @@ +User-Agent: * +Disallow: /drafts diff --git a/server.hs b/server.hs index c82b0f2..3c57426 100644 --- a/server.hs +++ b/server.hs @@ -4,6 +4,7 @@ import Control.Concurrent (forkIO) import qualified Data.ByteString as BS (ByteString, pack) import Data.Maybe (fromMaybe, mapMaybe) import Data.Monoid ((<>)) +import Data.Streaming.Network (HostPreference) import Data.String (fromString) import qualified Data.Text as T (Text, concat, pack) import qualified Data.Text.Encoding as TE (encodeUtf8) @@ -15,8 +16,8 @@ import Network.Wai.Application.Static (defaultWebAppSettings, ssIndices, ssMaxAge, ssRedirectToIndex, staticApp) -import Network.Wai.Handler.Warp (defaultSettings, run, - setPort) +import Network.Wai.Handler.Warp (defaultSettings, runSettings, + setHost, setPort) import Network.Wai.Handler.WarpTLS (runTLS, tlsSettingsChain) import Network.Wai.Middleware.AddHeaders (addHeaders) @@ -94,7 +95,7 @@ cspHeadersMiddleware = addHeaders <> " https://cdn.mathjax.org https://connect.facebook.net" <> " https://*.twitter.com https://cdn.syndication.twimg.com" <> " https://gist.github.com" - <> " https://*.google-analytics.com/ga.js" + <> " https://*.google-analytics.com" , "img-src 'self' https: data: platform.twitter.com" , "font-src 'self' data: https://use.typekit.net" <> " https://cdn.mathjax.org" @@ -131,10 +132,12 @@ deindexifyMiddleware app req sendResponse = -- debugging purposes. listen :: Int -> Application -> IO () listen port app = do + let settings = setHost "*6" (setPort port defaultSettings) + -- Inform which port we will be listening on. putStrLn $ "Listening on port " ++ show port ++ "..." -- Serve the WAI app using Warp - run port app + runSettings settings app -- | Serves a WAI Application on the specified port. -- The target port is printed to stdout before hand, which can be useful for @@ -149,7 +152,7 @@ listenTLS port app = do (fromMaybe "cert.pem" certPath) [fromMaybe "fullchain.pem" chainPath] (fromMaybe "privkey.pem" keyPath) - let settings = setPort port defaultSettings + let settings = setHost "*6" (setPort port defaultSettings) -- Inform which port we will be listening on. putStrLn $ "Listening on port " ++ show port ++ " (TLS)..." diff --git a/site.hs b/site.hs index b207f5c..31ad74a 100644 --- a/site.hs +++ b/site.hs @@ -25,7 +25,10 @@ data SiteConfiguration = SiteConfiguration hakyllConf :: Configuration hakyllConf = defaultConfiguration { deployCommand = - "rsync -ave 'ssh' _site/* chromabits.com:/www/chromabits.com" + "rsync -ave 'ssh' _site/* 45.79.220.75:/var/www/chromabits " ++ + "&& rsync -ave 'ssh' " ++ + ".stack-work/install/x86_64-linux/lts-5.2/7.10.3/bin/server " ++ + "45.79.220.75:/opt/chromabits" } siteConf :: SiteConfiguration @@ -80,6 +83,10 @@ main = hakyllWith hakyllConf $ do route $ setExtension "txt" compile copyFileCompiler + match "robots.txt" $ do + route $ setExtension "txt" + compile copyFileCompiler + match "bower_components/font-awesome/fonts/*" $ do route $ gsubRoute "bower_components/font-awesome/" (const "") compile copyFileCompiler diff --git a/templates/default.html b/templates/default.html index 5197471..4b02c03 100644 --- a/templates/default.html +++ b/templates/default.html @@ -73,13 +73,13 @@ </script> <script> - var _gaq=[['_setAccount','$gaId$'],['_trackPageview']]; - (function(d,t){ - var g=d.createElement(t), - s=d.getElementsByTagName(t)[0]; - g.src='https://ssl.google-analytics.com/ga.js'; - s.parentNode.insertBefore(g,s) - }(document,'script')); + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', 'UA-47694260-1', 'auto'); + ga('send', 'pageview'); </script> </body> </html> -- GitLab