leaflink-proxy-server v0.0.4
Leaflink Proxy Server
Proxy server for developing API driven applications locally.
Why
Our webpack build process is slow, really slow. This package aims to enhance Storybook driven development by allowing you to mount full Vue/Vuex apps directly in storybook & have all API enpoints work the same way as if you were working on the Leaflink platform itself.
Note: This is still pretty experimental. Issues may come up.
How it works
This server works by spoofing the identity of an already logged in user on the Leaflink platform. When the server starts, you'll provide a sessionid & csfrtoken corresponding to a currently logged in user on the platform. The proxy will apply these values either as a Cookie for GET requests or as a X-CSFRToken for POST, PATCH & DELETE.
Start the server: a.
yarn startif you're testing it using something like Postman OR b. Run the executableproxy-serverif you're installing as annpmpackageThe server will initialize on
http://localhost:3000by default.Authenticate:
With the server running, send a request to
/auth(http://localhost:3000/auth) containing the followingbodyparameters:
sessionidcsfrtokenExample:
const session = axios.create({ baseURL: 'http://localhost:3000' // Proxy default URL }); const result = await session.post('auth', { csfrtoken: 'lxxPqgEF8zW0GsKbW316abuoRWARxbmkeeCgfjMqDYsZUFCZbb0nxoiyGTDJ0FI4', sessionid: 'utvd6uee98h5povxq9cvmjk0ejifv69s' }); console.log(result) // Authentication set!You can find these values by opening the
Networkinspector tab & clicking on one of the requests made. They should be visible under aCookiessubtab.Note: At the moment, the authentication endpoint simply sets the token & session variables, it doesn't verify that they are actually valid. We'll want to enhance this.
Use the API
Once authenticated, all requests made to
http://localhost:3000/api/*will get forwarded to the Leaflink App.Make sure the token and sessionid you're passing in are fresh. If unsure, log out/in of the app to generate a fresh set of tokens.