papandreou / express-processimage

Express middleware that processes served images according to the query string
BSD 3-Clause "New" or "Revised" License
56 stars 18 forks source link

if i want to process the external server image ?? #28

Closed pradeepnidiganti closed 6 years ago

pradeepnidiganti commented 6 years ago

http://localhost:1337/bigImage.png?resize=400,300

rather than using the local image how to resize the external server image

papandreou commented 6 years ago

Assuming bigImage.png lives at https://externalhost.com/foo/bigImage.png you could accomplish this by adding a piece of proxying middleware after express-processimage (untested):

const proxy = require('http-proxy-middleware');

app.use('/externalImages', express()
  .use(require('express-processimage')())
  .use(proxy({target: 'https://externalhost.com/foo'}));

Then http://localhost:1337/externalImages/bigImage.png?resize=400,300 ought to work. Is that what you had in mind?

pradeepnidiganti commented 6 years ago

but i am getting another issue while using above example "Router.use() requires a middle-ware function but got a Object"

papandreou commented 6 years ago

Hmm, sounds like you're using a really old version of express? Could you try upgrading to 4.x?

pradeepnidiganti commented 6 years ago

No , i have used the latest version only the version of express is "express": "^4.16.2"

papandreou commented 6 years ago

Ah, is app an express.Router instance? I assumed it would be an express app:

const express = require('express');
const proxy = require('http-proxy-middleware');
const app = express();

app.use('/externalImages', express()
  .use(require('express-processimage')())
  .use(proxy({target: 'https://externalhost.com/foo'}));
pradeepnidiganti commented 6 years ago

Thnq i got it :+1: