-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 1.1 KB
/
index.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
var express = require('express');
var path = require('path');
var app = express();
var populate = require('./populate.js');
var persistence = require('./persistence.js');
app.set('port', (process.env.PORT || 5000));
app.get('/', function(request, response) {
let base_url = request.protocol + '://' + request.get('host') + request.originalUrl;
persistence.retrieve_urls(function(urls) {
for (let i = 0; i < urls.length; i++) {
urls[i].small_url = base_url + urls[i].small_url;
urls[i].medium_url = base_url + urls[i].medium_url;
urls[i].large_url = base_url + urls[i].large_url;
}
response.send(urls);
});
});
app.get('/*.jpg', function(request, response) {
let original_basename = path.basename(request.originalUrl);
persistence.retrieve_image(original_basename, function(err, image) {
if (err)
response.send('not found');
else
response.send(image.data);
});
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
populate.database();