Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
node_modules/*
node_modules
cache/*
tmp/*
npm-debug.log
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
# A simple node.js image resize service

## Config
This repository is a modification of https://github.com/tbasse/resize-server that is published by me to npm in order to make the image resizing service an express module.

- `appPort` The port the server will be listening on
- `appStdOut` Set to `false` to prevent stdout logging
- `convertCmd` Path to imagemagicks `convert`
- `cacheDirectory` Directory to save converted images to
I thank the author of the original repository for making such a great service.

## Installation

```
npm i --save express-resize-img
```

## Using in express

```js
let resizeApp = require('express-resize-img');
let express = require('express');
let app = express();

// hook the resizing service to a path on your application
app.use('/resize', resizeApp);

// run
app.listen(12345);
```

## Usage

Expand Down Expand Up @@ -42,7 +59,6 @@ http://serveraddress/`resize`/`output`/`url`
`http://serveraddress/h300/jpg/http://domain.com/image.jpg`
`http://serveraddress/w300/jpg,100/http://domain.com/image.jpg`


## License

(MIT License)
Expand Down
58 changes: 58 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

var express = require('express');
var fs = require('fs');
var bodyParser = require('body-parser');
var config = require('./config');
var log = require('./lib/log');
var RequestSplitter = require('./lib/requestsplitter');
var ResizeJob = require('./lib/resize').ResizeJob;

if (!fs.existsSync(config.cacheDirectory)) {
fs.mkdirSync(config.cacheDirectory);
}

var app = new express.Router();
app.use(bodyParser.json());

app.use(function (req, res, next) {
res.removeHeader('X-Powered-By');
next();
});

app.get('/health', function (req, res) {
res.send('OK').end();
});

app.get('/', function (req, res) {
res.send("Hello").end();
});

app.get(RequestSplitter.urlMatch, function (req, res) {
var now,
jobStartTime,
jobEndTime,
jobDuration;

now = jobStartTime = new Date().getTime();
var rs = new RequestSplitter(req.path, req.query);
var rj = new ResizeJob(rs.mapOptions(), function (err, file, cached) {
if (err) {
return res.json(err.status, err);
}

jobEndTime = new Date().getTime();
jobDuration = jobEndTime - jobStartTime;

if (cached) {
jobDuration = 0;
}
res.header('X-ResizeJobDuration', jobDuration);
res.header('Expires', new Date(now + config.cacheHeader.expires));
res.sendFile(file, {maxAge: config.cacheHeader.maxAge});
});

rj.startResize();
});

module.exports = app;
1 change: 0 additions & 1 deletion node_modules/.bin/express

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/jade

This file was deleted.

9 changes: 0 additions & 9 deletions node_modules/express/.npmignore

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/express/.travis.yml

This file was deleted.

Loading