forked from twopointone/image-resize-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (27 loc) · 847 Bytes
/
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
// This server is for development purposes. It wont be exported to lambda
var config = require('./config');
var express = require('express');
var app = express();
var lambda = require('./index.js');
// Match the lambda behaviour to generate the file and then serve from the destination bucket
app.use(express.static(config.DESTINATION_PATH));
app.get('/favicon.ico', function(req, res) {
res.send('');
});
app.get('*', function(req, res) {
var path = req.path;
var handlerEvent = {
queryStringParameters: {
key: path
}
};
function responseFunction(error, result) {
if (!error) {
res.writeHead(result.statusCode, result.headers);
res.end();
} else {
}
}
lambda.handler(handlerEvent, {}, responseFunction);
});
app.listen(config.PORT);