Serving files from a local CORS server for local development

Googling around, I found an awesome little script that allows you to transform python’s SimpleHTTPServer into a CORS enabled server.

I copied the above gist into a folder, then within that made a “data” folder where I put CSVs and JSON files for local projects I’m working on.

My CORS server file structure.

Now, when I need to work locally and use some of this data, I can plop it in there and spin up the server with

python cors_server.py

This creates a server that allows you to grab the files at localhost:31338/data/file_name. So when it’s time to grab the files, I can grab it with axios. Here’s an example from a Vue project I was just messing around with.

axios
  .get("http://localhost:31338/data/programs.json")
  .then(response => (this.programs = response.data.programs));

Cool little tip for working locally, enjoy!

Leave a comment

What do you think?

%d bloggers like this: