This repository has been archived by the owner on Jan 31, 2021. It is now read-only.
forked from Jonty/image-resizer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
66 lines (52 loc) · 1.46 KB
/
test.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
/**
This file is the working implementation of image-resizer used for development
purposes. It is a very close example of what is generated by the cli script
when provisioning a new instance. `image-resizer new`
*/
'use strict';
var express = require('express'),
app = express(),
ir = require('./index'),
env = ir.env,
Img = ir.img,
streams = ir.streams;
app.directory = __dirname;
ir.expressConfig(app);
/**
Return the modifiers map as a documentation endpoint
*/
app.get('/modifiers.json', function(request, response){
response.json(200, ir.modifiers);
});
/**
Some helper endpoints when in development
*/
if (env.development){
// Show a test page of the image options
app.get('/test-page', function(request, response){
response.render('index.html');
});
// Show the environment variables and their current values
app.get('/env', function(request, response){
response.json(200, env);
});
}
/*
Return an image modified to the requested parameters
- request format:
/:modifers/path/to/image.format:metadata
eg: https://doapv6pcsx1wa.cloudfront.net/s50/sample/test.png
*/
app.get('/:modifiers/*?', function(request, response){
var image = new Img(request);
image.getFile()
.pipe(new streams.identify())
.pipe(new streams.resize())
.pipe(new streams.filter())
.pipe(new streams.optimize())
.pipe(streams.response(request, response));
});
/**
Start the app on the listed port
*/
app.listen(app.get('port'));