System Requirements: Node 0.12.7 OR 0.10.x NPM
Execute npm install to download node modules required for execution
To Start Program:
Execute node app.js on root directory
Open your browser to http://localhost:3000 and you will be accessing google, through the proxy.
Customization can occur on the command line with the following arguments.
- host (optional, defaults to 'www.google.com')
- devHost <dev_hostname> (optional, defaults to 'localhost')
- useDBCaching (optional, defaults to false) DO NOT pass true without redis installed locally
- port (optional, defaults to 3000) -- HTTP Port Number
- sslPort (optional, defaults to 3001) -- HTTPS Port Number
Simple Express server, middleware is built using passed in parameters with defaults living in package.json.
Built with a simple enclosure that would enable multiple proxies to be set up to different hosts with different options.
Logical Steps:
- Check if request is cached a. If it is, respond immediately with the body b. Due to the fact that I added DB support, the data is returned asynchronously
- Determine appropriate protocol for request
- Handle binary encoding for Request module
- Make the request
- Handle any redirects
- Determine response size
- If the request responds with a 2XX response a. Attempt to cache request
- Set the headers of our response with that of the proxied request response
- Return status code and body
Cache is a Base Object that is storage agnostic. All of the logic for handling caching is built into Cache's prototype methods.
- Assigns options to an instance variable.
- Initialize storage object
- Starts the garbage collection method in an interval that runs every minute
- get a. Gets the cache object
- expire a. Expires the cache
- store a. Stores the cached object b. Handles all configuration checks (size/number)
- insert a. inserts into cache storage
- Find a. finds cache record
- Remove a. removes cache record
- Garbage Collection a. removes stale cache from storage
This storage object is a plain old javascript object {}.
This storage object is stored into a database so it is persistent across executions.