-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
173 lines (158 loc) · 5.07 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//Requirements and Config
require("datejs");
require("marko/node-require").install();
require("marko/express");
var subdomain = require('express-subdomain');
var express = require("express");
var indexTemplate = require("./index.marko");
const config = require("./config").config;
var favicon = require("serve-favicon");
var path = require("path");
var http = require("http");
var app = express();
var port = process.env.PORT || 8080;
var compression = require("compression");
app.use(compression());
app.use(favicon(path.join(__dirname, "public", "favicon.ico")));
//Build the showlists
var showList = require("./lib/showlist");
var nycshowlist = new showList(config.zipCode, "concertCache");
var phillyshowlist = new showList("19102", "phillyconcertCache");
var denvershowlist = new showList("80012", "denverconcertCache");
var seattleshowlist = new showList("98101", "seattleconcertCache");
var chicagoshowlist = new showList("60611", "chicagoconcertCache");
var lashowlist = new showList("90041", "laconcertCache");
var austinshowlist = new showList("78701", "austinconcertCache");
var dcshowlist = new showList("20001", "dcconcertCache");
//Update Data Script on the Hour
var ontime = require("ontime");
ontime(
{
cycle: ["12:00:00"]
},
function(ot) {
console.log("Updating From API");
nycshowlist.update(function(){
phillyshowlist.update(function(){
denvershowlist.update(function(){
seattleshowlist.update(function(){
chicagoshowlist.update(function(){
lashowlist.update(function(){
austinshowlist.update(function(){
dcshowlist.update(function(){
console.log("all cities Updated");
});
});
});
});
});
});
});
});
ot.done();
return;
}
);
//Lasso Pack Page
var isProduction = process.env.NODE_ENV === "production";
require("lasso").configure({
plugins: ["lasso-marko"],
outputDir: __dirname + "/static",
bundlingEnabled: isProduction,
minify: isProduction,
fingerprintsEnabled: isProduction
});
//Routes
var phillyr = express.Router();
app.use(subdomain('philly', phillyr));
//api specific routes
phillyr.get('/', function(req, res) {
res.marko(indexTemplate, {
events: phillyshowlist.theShowList,
numevents: phillyshowlist.theShowList.length.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","),
city: "Philly"
});
});
var denr = express.Router();
app.use(subdomain('denver', denr));
//api specific routes
denr.get('/', function(req, res) {
res.marko(indexTemplate, {
events: denvershowlist.theShowList,
numevents: denvershowlist.theShowList.length.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","),
city: "Denver"
});
});
var dcr = express.Router();
app.use(subdomain('dc', dcr));
//api specific routes
dcr.get('/', function(req, res) {
res.marko(indexTemplate, {
events: dcshowlist.theShowList,
numevents: dcshowlist.theShowList.length.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","),
city: "DC"
});
});
var austinr = express.Router();
app.use(subdomain('austin', austinr));
//api specific routes
austinr.get('/', function(req, res) {
res.marko(indexTemplate, {
events: austinshowlist.theShowList,
numevents: austinshowlist.theShowList.length.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","),
city: "Austin"
});
});
var lar = express.Router();
app.use(subdomain('la', lar));
//api specific routes
lar.get('/', function(req, res) {
res.marko(indexTemplate, {
events: lashowlist.theShowList,
numevents: lashowlist.theShowList.length.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","),
city: "LA"
});
});
var chir = express.Router();
app.use(subdomain('chicago', chir));
//api specific routes
chir.get('/', function(req, res) {
res.marko(indexTemplate, {
events: chicagoshowlist.theShowList,
numevents: chicagoshowlist.theShowList.length.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","),
city: "Chicago"
});
});
var seatr = express.Router();
app.use(subdomain('seattle', seatr));
//api specific routes
seatr.get('/', function(req, res) {
res.marko(indexTemplate, {
events: seattleshowlist.theShowList,
numevents: seattleshowlist.theShowList.length.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","),
city: "Seattle"
});
});
//Static Files
app.get("/static/*", function(req, res, next) {
//lasso middleware doesn't put cache-control, route to force Cache Control Headers for static content, then send it to lasso middleware
res.setHeader("Cache-Control", "public, max-age=2592000");
res.setHeader("Expires", new Date(Date.now() + 2592000000).toUTCString());
app.use(require("lasso/middleware").serveStatic());
next();
});
//Main Route for NYC
app.get("/", function(req, res) {
res.marko(indexTemplate, {
events: nycshowlist.theShowList,
numevents: nycshowlist.theShowList.length.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","),
city: config.cityName
});
});
//Start Server
app.listen(port, function() {
console.log("server on port:" + port);
if (process.send) {
process.send("online");
}
});