Part of Udacity's Full-Stack nanodegree
NOTE While using hex colors make sure to encode # as %23 since the hash symbol is used by the browser!
- To install required dependencies run
npm ioryarn - Create a new
.envfile and set variables written in.env.templatePORTis the part number to be used by the serverIMAGES_DIRis the directory name to get images from, defaults to "images"CACHE_DIRis the directory name to get cached images from, defaults to "cache"
npm run devoryarn devstarts a development server on the port in the.envfilenpm run buildoryarn buildbuilds the project for production inbuilddirectorynpm run jasmineoryarn jasmineruns jasmine for unit tesingnpm run testoryarn testbuilds the project then runs the unit testsnpm run lintoryarn lintruns eslint to check for style or code issues.npm run lint:fixoryarn lint:fixsimilar to the previous but tries to fix all auto fixable issuesnpm run prettieroryarn prettierruns prettier to improve & fix writing stylenpm run startoryarn startruns the production build using the.envfile (need the project to be build beforehand)
After starting the server you can check the functionality of the project as detailed below
- Send a
GETrequest tohttp://localhost:${PORT}/placeholder?width={width}&height={height}replacePORTwith your port number that is added in the.envfile & replace both{width}&{height}with your desired ints
GET http://localhost:8080/placeholder?width=250&height=250
A CSS supported color to be applied on the background of the placeholder image
GET http://localhost:8080/placeholder?width=250&height=250&bgColor=cornflowerblue
A CSS supported color to be applied on the text of the placeholder image
GET http://localhost:8080/placeholder?width=250&height=250&textColor=%23e5e5e5
A string containing the text to be in the image
GET http://localhost:8080/placeholder?width=250&height=250&textColor=%23e5e5e5&text=Hello, World!
- Send a
GETrequest tohttp://localhost:${PORT}/resize?width={width}&height={height}&filename={filename}replacePORTwith your port number that is added in the.envfile & replace both{width}&{height}with your desired ints, filename should be replaced with a file inside theIMAGES_DIRadded in the.envfile (along with the extension)
GET http://localhost:8080/resize?width=250&height=250&filename=scandanavia-01.jpeg
Instead of using the filesystem you can just enter a url of an image
GET http://localhost:8080/resize?width=250&height=250&url=https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png
If you wanted to fetch a png file but wants it to be compressed using webp or jpeg encoding you can pass the type parameter with 3 possible values webp, png, jpeg
It compresses the file on the fly
GET http://localhost:8080/resize?width=250&height=250&filename=scandanavia-01.jpeg&type=webp