Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the right way to include a browser REPL on a page, but only in development?

I'm using Austin to set up a browser-connected REPL, and following the example of its sample project, which uses Enlive to add the REPL script to the page.

Now I'd like to deploy my app, but I don't wan't Austin or my REPL to be on the page in production. What's the intended way to use the REPL only in development?

Is there a way to use Enlive as a middleware I could use in development and not in production?

like image 256
Peeja Avatar asked Sep 16 '14 01:09

Peeja


People also ask

How do I create a REPL?

One way is to click on the Create Repl button located at the top left hand corner of the homepage. You can also create a repl by clicking on the + icon under the Create section. The last option is the click on the + icon located at the upper right hand corner.

What is REPL and how does it work?

The acronym REPL stands for read-eval-print loop and basically provides a programmer with an interactive programming environment. Unsurprisingly, that’s exactly what Repl.it gives you, too, and with 200,000 weekly active developers on the platform already, there is clearly a demand for this service.

What programming languages does replit support?

Repl.it already supports virtually every programming language you can think of, no matter whether that’s JavaScript, Python, PHP or QBasic, as well as popular frameworks like Django, Ruby on Rails and Sinatra. And if you want to hurt yourself and write in Brainfuck, you can do that, too.

What is replit and how to use it?

Replit is a popular free online IDE that you can use to create your projects with very little setup. This editor supports over 50 languages and many programming courses use it, including freeCodeCamp. In this article, I will show you how to get started with Replit and show you how to use a lot of the basic features.


1 Answers

There's almost always something that uniquely distinguishes a production environment from :dev that you can use as a conditional: if in :dev, inject the result of (browser-connected-repl-js); if not, don't.

If your deployment environment doesn't have such a property, I'd suggest adding one, as this sort of "only in environment X" use case is pretty common for a lot of things.


On the other hand, if you're looking to avoid having Austin and its dependencies included in your production-targeted builds entirely without changing any of your code that uses browser-connected-repl-js, one solution might be to simply dummy up the relevant Austin namespace, e.g.:

(ns cemerick.austin.repls)

(defn browser-connected-repl-js [& _] "")

Put that in cemerick/austin/repls.clj in a directory that is included in your project.clj's non-:dev profile:source-paths. Now your code will deploy to production without Austin and its dependencies, and your code will transparently call the above dummy function (injecting nothing into your page(s)).

like image 148
cemerick Avatar answered Dec 31 '22 19:12

cemerick