Remy Sharp on twitter asked
If anyone uses @js_bin to inject via POST (@triblondon et al?), it would super if you could contrib to this article https://t.co/VunzpXBC0M
— Remy Sharp (@rem) June 24, 2015
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
This gist is an exploration of said feature, in order to better describe it.
Remy quickly pointed out that a request was made by a user for
precisly this feature. The comment in the request have served as a
starting point for my investigations.
The discussion for the feature request mentions the JS Bin
API. Furthermore a utility called inliner shows an example
how to use the API.
In order to test my understanding of the API I would like to test
locally. Luckily it is possible to
run JS Bin on your machine. I Installed jsbin
with
npm.
unfortunatly that ran into errors because of a known issue. After
downgrading to node to 0.10.x
, it was possible to install jsbin
just fine.
JS Bin can be configured with a configuration file. I copied the
default configuration file from
/usr/local/lib/node_modules/jsbin/config.default.json
to
config.local.json
.
It adopted it to fit my current needs, i.e. allow read-write access
without authentication.
{
"api": {
"allowAnonymousReadWrite": true,
"allowAnonymousRead": true,
"requireSSL": false
}
}
The JSBIN_CONFIG
environment variable must point to the
configuration file, this can be done with the following command
JSBIN_CONFIG=./config.local.json jsbin
The next command
curl -v -X POST http://localhost:3000/api/save -d "html=a"
responds with the following error
* Hostname was NOT found in DNS cache
* Trying ::1...
* connect to ::1 port 3000 failed: Connection refused
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> POST /api/save HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:3000
> Accept: */*
> Content-Length: 6
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 6 out of 6 bytes
< HTTP/1.1 500 Internal Server Error
< X-Powered-By: Express
< Content-Type: text/plain
< Date: Wed, 24 Jun 2015 14:56:08 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact
Error: SQLITE_READONLY: attempt to write a readonly database~
The same problem occurs when I use the web UI to clone a bin.

A similar problem was mentioned in [issue 1251][issue 1251].