Compare commits

...

3 Commits

Author SHA1 Message Date
Vic 30775e7b41 updated readme 2 years ago
Vic ac382953b1 minor fixes 2 years ago
Vic 8929d7d41a added test with jasmine 2 years ago

@ -1,25 +1,28 @@
# Resize-Api
The resize API allow to place images into your frontend with the size set via URL parameters for rapid prototyping
The resize API allow to place images into your frontend with the size set via URL parameters for rapid prototyping.
A library to serve properly scaled versions of your images to the front end to reduce page load size
A library to serve properly scaled versions of your images to the front end to reduce page load size.
Rather than needing to resize and upload multiple copies of the same image to be used throughout your site, the API handle resizing and serving stored images.
# Installation
1- Install packages dependencies
1- Install packages dependencies.
`npm install`
2- build the project
2- build the project.
`npm build`
3- run the node server
3- run the node server.
`node ./build/index`
You can also run the code through the nodemon devepement server
You can also run the code through the nodemon devepement server.
`npm run start`
When the server is running, you can resize an image by going to this url and adding parameters to resize the image `http://localhost:5000/api/image?filename=encenadaport&width=200&height=200`
When the server is running, you can resize an image availible in the `images/full` folder by going to the following url and adding parameters to resize the image.
`http://localhost:5000/api/image?filename=encenadaport&width=200&height=200`
# Built with
@ -30,4 +33,5 @@ When the server is running, you can resize an image by going to this url and add
- Git
# Author
Anis Benziane

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

@ -24,6 +24,7 @@
"@types/jasmine": "^3.10.3",
"@types/node": "^17.0.9",
"@types/sharp": "^0.29.5",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"eslint": "^8.7.0",
@ -31,13 +32,14 @@
"eslint-plugin-prettier": "^4.0.0",
"jasmine": "^4.0.2",
"jasmine-spec-reporter": "^7.0.0",
"nodemon": "^2.0.15",
"ts-node": "^10.4.0",
"typescript": "^4.5.4"
},
"dependencies": {
"express": "^4.17.2",
"nodemon": "^2.0.15",
"path": "^0.12.7",
"sharp": "^0.29.3"
"sharp": "^0.29.3",
"supertest": "^6.2.2"
}
}

@ -1,20 +1,16 @@
import express from 'express';
import routes from './routes/routesIndex'
import express from 'express'
import routes from './routes/index'
const app = express();
const port = 3000;
// app.get('/api', (req, res) => {
// res.send('welcome to api');
// })
// get routes
app.use('/api', routes)
// start Express server
app.listen(port, () => {
console.log(`server started at http://localhost:${port}`);
})
export default app;

@ -49,6 +49,9 @@ image.get('/', async (req: express.Request, res: express.Response): Promise<void
} else if (fileName) {
// display original image if we only have filename parameter in the request
res.sendFile(inputimgPath);
} else {
res.status(404).send("Something went wrong");
return;
}
})

@ -0,0 +1,42 @@
import app from "../index"
import image from "../routes/api/image"
import supertest from "supertest"
const request = supertest(app);
// Endpoint testing
describe('Test endpoint responses', () => {
it('Get the api endpoint', async () => {
const response = await request.get('/api/image?filename=fjord');
expect(response.status).toBe(200);
})
it('Throw an error if the image name is incorrect', async () => {
const response = await request.get('/api/image?filename=test');
expect(response.status).toBe(404);
})
it('Working if we only have a filename in the url', async () => {
const response = await request.get('/api/image?filename=encenadaport');
expect(response.status).toBe(200);
})
})
// Image resize test
describe('Test of the image endpoint with resize', () => {
it('Resize working with filename and width parameter', async () => {
const response = await request.get('/api/image?filename=encenadaport&height=200');
expect(response.status).toBe(200);
})
it('Resize working with filename and height parameter', async () => {
const response = await request.get('/api/image?filename=encenadaport&width=200');
expect(response.status).toBe(200);
})
it('Resize working with filename and width, height parameter', async () => {
const response = await request.get('/api/image?filename=encenadaport&height=200');
expect(response.status).toBe(200);
})
})

@ -98,5 +98,5 @@
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"exclude": ["node_modules", "build", "spec"]
"exclude": ["node_modules", "build"]
}

Loading…
Cancel
Save