-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
217 lines (155 loc) · 6.69 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
var express = require('express');
var app = express();
var request = require('request');
//LOGGING MIDDLEWARE
var logger = require('morgan');
app.use(logger('dev'));
//var mongoose = require('mongoose');
//mongoose.connect('mongodb://localhost/ProjectSnowshoe', (err) => {
// if(err) {
// console.log("Bad news:", err)
// } else {
// console.log("Mongoose connected!")
// }
//});
// console.log(process.env);
var APP_DIR=process.env.APP_DIR
var APIKEY =process.env.APIKEY
var HTTP = require('http');
var HTTPS = require('https');
fs = require('fs');
// ports = {
// http: process.env.PORT || 8080,
// https: process.env.PORT_SSL || 443
// };
//MIDDLEWARE THAT WILL REDIRECT ALL TRAFFIC TO HTTPS
app.all('*', ( req, res, next ) => {
if( req.protocol === 'http://' ) {
res.set('X-Forwarded-Proto','https');
res.redirect('https://'+ req.headers.host + req.url);
console.log("MIDDLEWARE HTTP TO HTTPS:", req);
} else {
next();
}
});
//=================API CALLS================================
//app.get('/', function (req, res) {
// request(URL, callback) takes the parameters for the API URL and a callback function
// this API call will return result=[{album, track, lyrics}...]
// request('https://api.darksky.net/forecast/'+process.env.APIKEY+'/38.911024,-107.031255', function (err, response, body) {
// var parseBody = JSON.parse(body)
// var weather = parseBody.result.map
// })
// console.log(weather);
// });
//=================ROUTE VARIABLES==========================
crestedURL = 'https://api.darksky.net/forecast/'+APIKEY+'/38.911024,-107.031255';
friscoURL = 'https://api.darksky.net/forecast/'+APIKEY+'/39.7292,-105.9047';
indianPeaksURL = 'https://api.darksky.net/forecast/'+APIKEY+'/39.9614, -105.5108';
kenoshaURL = 'https://api.darksky.net/forecast/'+APIKEY+'/39.4133,-105.7567';
mosquitoURL = 'https://api.darksky.net/forecast/'+APIKEY+'/39.2814,-106.1861';
rmnpURL = 'https://api.darksky.net/forecast/'+APIKEY+'/40.3292,-105.5933';
steamboatURL = 'https://api.darksky.net/forecast/'+APIKEY+'/40.3847,-106.6117';
wpURL = 'https://api.darksky.net/forecast/'+APIKEY+'/39.8472,-105.9117';
//==================ROUTE FOR CRESTEDBUTTE===================
app.get('/forecast/38.911024,-107.031255', function(req,res) {
request.get(crestedURL,function(error,response,body){
res.send(body) })})
//==================ROUTE FOR FRISCO=========================
app.get('/forecast/39.7292,-105.9047', function(req,res) {
request.get(friscoURL,function(error,response,body){
res.send(body) }) })
//==================ROUTE FOR INDIAN PEAKS===================
app.get('/forecast/39.9614,-105.5108', function(req,res) {
request.get(indianPeaksURL,function(error,response,body){
res.send(body) }) })
//==================ROUTE FOR KENOSHA PASS===================
app.get('/forecast/39.4133,-105.7567', function(req,res) {
request.get(kenoshaURL,function(error,response,body){
res.send(body) }) })
//==================ROUTE FOR MOSQUITO PASS==================
app.get('/forecast/39.2814,-106.1861', function(req,res) {
request.get(mosquitoURL,function(error,response,body){
res.send(body) }) })
//==================ROUTE FOR ROCKY MOUNTAIN=================
app.get('/forecast/40.3292,-105.5933', function(req,res) {
request.get(rmnpURL,function(error,response,body){
res.send(body) }) })
//==================ROUTE FOR STEAMBOAT SPRINGS==============
app.get('/forecast/40.3847,-106.6117', function(req,res) {
request.get(steamboatURL,function(error,response,body){
res.send(body) }) })
//==================ROUTE FOR WINTER PARK====================
app.get('/forecast/39.8472,-105.9117', function(req,res) {
request.get(wpURL,function(error,response,body){
res.send(body) }) })
//==================ROUTE FOR MAIN PAGE=====================
app.get('/', function(req, res){
res.sendFile("index.html", { root: './Public/html' })
});
//==================ROUTE FOR DISCOVER PAGE=================
app.get('/discover', function(req, res) {
res.sendFile("discover.html", { root: './Public/html'})
});
//=================ROUTE FOR FIND PAGE======================
app.get('/find', function(req, res) {
res.sendFile("find.html", { root : './Public/html'})
});
//==================ROUTE FOR CRESTED BUTTE PAGE============
app.get('/discover/CrestedButte', function(req, res) {
res.sendFile("crestedButte.html", { root : './Public/html'})
});
//==================ROUTE FOR FRISCO PAGE===================
app.get('/discover/Frisco', function(req, res) {
res.sendFile("frisco.html", { root : './Public/html'})
});
//==================ROUTE FOR INDIAN PEAKS PAGE============
app.get('/discover/IndianPeaks', function(req, res) {
res.sendFile("indianpeaks.html", { root : './Public/html'})
});
//==================ROUTE FOR KENOSHA PASS PAGE============
app.get('/discover/Kenosha', function(req, res) {
res.sendFile("kenosha.html", { root : './Public/html'})
});
//==================ROUTE FOR MOSQUITO PASS PAGE============
app.get('/discover/Mosquito', function(req, res) {
res.sendFile("mosquito.html", { root : './Public/html'})
});
//==================ROUTE FOR RMNP PAGE============
app.get('/discover/RMNP', function(req, res) {
res.sendFile("rmnp.html", { root : './Public/html'})
});
//==================ROUTE FOR STEAMBOAT PAGE============
app.get('/discover/Steamboat', function(req, res) {
res.sendFile("steamboat.html", { root : './Public/html'})
});
//==================ROUTE FOR WINTER PARK PAGE============
app.get('/discover/WinterPark', function(req, res) {
res.sendFile("wp.html", { root : './Public/html'})
});
console.log(APP_DIR);
app.use(express.static('./Public'))
// start an http server listening on the default port
// HTTP.createServer(app).listen(ports.http);
// start an https server listening on the default port
var PORT = process.env.PORT || 8080
app.listen(PORT, function(err) {
if (err) {
console.log("There was an error connecting:", err);
} else {
console.log("Connection up and running on port", PORT);
}
});
// try {
// var httpsConfig = { // https://nodejs.org/api/https.html
// key: fs.readFileSync('/etc/letsencrypt/live/www.projectsnowshoe.com/privkey.pem'),
// cert: fs.readFileSync('/etc/letsencrypt/live/www.projectsnowshoe.com/cert.pem'),
// key: fs.readFileSync('/etc/letsencrypt/live/projectsnowshoe.com/privkey.pem'),
// cert: fs.readFileSync('/etc/letsencrypt/live/projectsnowshoe.com/cert.pem')
//
// };
// HTTPS.createServer( httpsConfig, app ).listen( ports.https );
// console.log("Server up and running via HTTPS");
// } catch (e) {
// console.error('Could not HTTPS server:', e);
// }