@@ -18,67 +18,57 @@ var MobileDetect = require('mobile-detect');
1818var express = require ( 'express' ) ;
1919var chalk = require ( 'chalk' ) ;
2020var bp = require ( 'body-parser' ) ;
21- var swig = require ( 'swig' ) ;
21+ var nunjucks = require ( 'nunjucks' ) ;
22+ var morgan = require ( 'morgan' ) ;
23+ var ac = require ( 'appcache-node' ) ;
2224
23-
24- //var ac = require('appcache-node');
2525var app = express ( ) ;
26+
2627// Create a cache for offline access, invalidate each hour.
2728// add manifest="app.cache" to app_layout and index_layout
28- // var cache = ac.newCache(["components/bootstrap/dist/css/bootstrap.css",
29- // "components/bootstrap/dist/js/bootstrap.min.js",
30- // "components/howler/howler.min.js",
31- // "components/animate.css/animate.css",
32- // "components/jquery/dist/jquery.min.js",
33- // "components/ionicons/css/ionicons.css",
34- // "components/icomoon/dist/css/style.css",
35- // "css/stylish-portfolio.css",
36- // "css/modern-buttons.css",
37- // "css/fonts.css",
38- // "css/app/index.css",
39- // "css/real-world.css",
40- // "css/fonts/Averia/averia_sans_libre_regular.svg",
41- // "css/fonts/Averia/averia_sans_libre_regular.ttf",
42- // "css/fonts/Averia/averia_sans_libre_regular.woff",
43- // "css/fonts/Catull.svg",
44- // "css/fonts/Catull.ttf",
45- // "css/fonts/Catull.woff",
46- // "components/icomoon/dist/fonts/icomoon.svg",
47- // "components/icomoon/dist/fonts/icomoon.ttf",
48- // "components/icomoon/dist/fonts/icomoon.woff",
49- // "components/ionicons/fonts/ionicons.svg?v=2.0.0#Ionicons",
50- // "components/ionicons/fonts/ionicons.ttf?v=2.0.0",
51- // "components/ionicons/fonts/ionicons.woff?v=2.0.0",
52- // "components/bootstrap/dist/css/bootstrap.css.map",
53- // "components/jquery/dist/jquery.min.map",
54- // "sounds/chicken.wav",
55- // "sounds/ignore.wav",
56- // "sounds/glados_s6.wav",
57- // "sounds/glados_s7.wav",
58- // "sounds/glados_s8.wav",
59- // "sounds/glados_s9.wav",
60- // "sounds/glados_s10.wav",
61- // "js/app/index.js",
62- // ])
63- // cache += "\nNETWORK:\n*"
29+ var cache = ac . newCache ( [ "components/bootstrap/dist/css/bootstrap.css" ,
30+ "components/howler/howler.min.js" ,
31+ "sounds/chicken.wav" ,
32+ "sounds/ignore.wav" ,
33+ "sounds/glados_s6.wav" ,
34+ "sounds/glados_s7.wav" ,
35+ "sounds/glados_s8.wav" ,
36+ "sounds/glados_s9.wav" ,
37+ "sounds/glados_s10.wav" ,
38+ ] )
39+ cache += "\nNETWORK:\n*"
6440
6541var googol = chalk . blue ( "g" ) + chalk . red ( "o" ) + chalk . yellow ( "o" ) + chalk . blue ( "g" ) + chalk . red ( "o" ) + chalk . green ( "l" ) ;
6642var glados = chalk . yellow ( "g" ) + chalk . green ( "l" ) + chalk . red ( "a" ) + chalk . blue ( "d" ) + chalk . red ( "o" ) + chalk . blue ( "s" ) ;
6743
68- // Express settings.
44+ // Express settings and middleware .
6945app . set ( 'port' , ( process . env . PORT || 5000 ) ) ;
70- app . engine ( 'html' , swig . renderFile ) ;
7146app . set ( 'view engine' , 'html' ) ;
7247app . set ( 'views' , __dirname + '/views' ) ;
7348app . use ( express . static ( __dirname + '/public' ) ) ;
7449app . disable ( 'x-powered-by' ) ;
7550
76- // Swig custom filters.
51+ if ( app . settings . env == "development" ) {
52+ app . use ( morgan ( 'dev' ) )
53+ } else {
54+ app . use ( morgan ( 'combined' ) )
55+ }
56+
57+ // Configure view template for nunjucks.
58+ var nunjucksTemplate = nunjucks . configure ( 'views' , {
59+ autoescape :true ,
60+ express :app
61+ } ) ;
7762
78- // Select a random item in an array.
79- swig . setFilter ( 'random' , function ( array ) {
63+ nunjucksTemplate . addFilter ( 'random' , function ( array ) {
8064 return array [ Math . floor ( Math . random ( ) * array . length ) ]
81- } )
65+ } ) ;
66+
67+ // Nunjucks custom filters.
68+ nunjucksTemplate . addFilter ( 'json' , function ( obj ) {
69+ return JSON . stringify ( obj ) ;
70+ } ) ;
71+
8272
8373// Configuration
8474
@@ -99,22 +89,24 @@ if (!process.env.SHOW_RELEASE_NAME) {
9989 version [ 'show_release_name' ] = process . env . SHOW_RELEASE_NAME
10090}
10191
102- // Cache
103- // app.all('/app.cache', function(req, res){
104- // res.writeHead(200, {'Content-Type': 'text/cache-manifest'});
105- // res.end(cache);
106- // })
92+ // Display app cache.
93+ app . all ( '/app.cache' , function ( req , res ) {
94+ res . writeHead ( 200 , { 'Content-Type' : 'text/cache-manifest' } ) ;
95+ res . end ( cache ) ;
96+ } )
10797
10898// Routes.
10999
110100// Index.
111101app . get ( '/' , function ( req , res ) {
102+ var ismob = isMobile ( req )
112103 on_heroku = process . env . ON_HEROKU
113104 footerWords = [ 'Made' , 'Crafted' , 'Designed' , 'Built' , 'Created' ]
114105 date = new Date ( )
115- res . render ( "index" , {
106+ res . render ( "index.html " , {
116107 words : footerWords ,
117108 on_heroku : on_heroku ,
109+ mob :ismob ,
118110 v : version ,
119111 year :date . getFullYear ( )
120112 } )
@@ -131,20 +123,32 @@ app.all('/robots.txt', function(req, res) {
131123 res . end ( robotstxt )
132124} ) ;
133125
134- // Nope .
135- app . get ( '/nope' , function ( req , res , next ) {
126+ // User-Agent Checker .
127+ function isMobile ( req ) {
136128 md = new MobileDetect ( req . headers [ 'user-agent' ] )
137129 if ( md . mobile ( ) || md . is ( "Console" ) || md . is ( "Watch" ) || md . is ( "MobileBot" ) || md . match ( "\b(Nintendo|Nintendo WiiU|Nintendo 3DS|PLAYSTATION|Xbox)\b" ) ) {
130+ return true
131+ } else {
132+ return false
133+ }
134+ }
135+
136+ // Nope.
137+ app . get ( '/nope' , function ( req , res , next ) {
138+ if ( isMobile ( req ) == true ) {
138139 res . render ( "toobad" , { device :md . mobile ( ) } )
139140 } else {
140141 res . redirect ( "/" )
141142 }
142143} ) ;
143144
145+ app . get ( '/end' , function ( req , res ) {
146+ res . redirect ( "/" )
147+ } )
148+
144149// App
145150app . get ( '/app' , function ( req , res ) {
146- md = new MobileDetect ( req . headers [ 'user-agent' ] )
147- if ( md . mobile ( ) || md . is ( "Console" ) || md . is ( "Watch" ) || md . is ( "MobileBot" ) || md . match ( "\b(Nintendo|Nintendo WiiU|Nintendo 3DS|PLAYSTATION|Xbox)\b" ) ) {
151+ if ( isMobile ( req ) == true ) {
148152 res . render ( "toobad" , { device :md . mobile ( ) } )
149153 } else {
150154 exists = req . get ( 'X-IS-GGS' )
0 commit comments