-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (49 loc) · 1.61 KB
/
app.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
var express = require('express');
var app = express();
var path = require('path');
var bodyParser = require('body-parser');
var unsplash = require('unsplash-api');
var dotenv = require('dotenv').load();
var port = process.env.PORT || 3000;
var clientId = process.env.clientId;
unsplash.init(clientId);
app.get('/', function(req, res){
unsplash.searchPhotos('puppies', null, 7, 30, function(error, photos, link) {
res.render('pages/index', {
photos: photos
});
});
})
app.get('/puppies', function(req, res){
var pageCount = 10,
currentPage = 1;
//set current page if specifed as get variable (eg: /?page=2)
if (typeof req.query.page !== 'undefined') {
currentPage = +req.query.page;
};
unsplash.searchPhotos('puppies', null, currentPage, 15, function(error, photos, link) {
res.render('pages/puppies', {
photos: photos,
link: link,
pageCount: pageCount,
currentPage: currentPage
});
});
});
app.get('/cart', function(req, res){
res.render('pages/cart');
});
app.get('/checkout', function(req, res){
res.render('pages/checkout');
});
// View engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
// Set static path
app.use(express.static(__dirname + '/public'));
app.use('/js', express.static(__dirname + '/node_modules/bootstrap/dist/js')); // redirect bootstrap JS
app.use('/js', express.static(__dirname + '/node_modules/jquery/dist')); // redirect JS jQuery
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css')); // redirect CSS bootstrap
app.listen(port, function() {
console.log('Our app is running on http://localhost:' + port);
});