Skip to content

Instantly share code, notes, and snippets.

@dvberkel
Last active August 29, 2015 14:23
Show Gist options
  • Save dvberkel/89370062073cc673bc4d to your computer and use it in GitHub Desktop.
Save dvberkel/89370062073cc673bc4d to your computer and use it in GitHub Desktop.
Exploration of JSBin Pre-populate bin option
{
"env": "development",
"timezone": "UTC",
"url": {
"host": "localhost:3000",
"prefix": "/",
"ssl": false,
"static": false,
"runner": false
},
"max-request-size": "1MB",
"store": {
"adapter": "sqlite",
"sqlite": {
"location": "jsbin.sqlite"
},
"mysql": {
"host": "localhost",
"user": "root",
"password": "",
"database": "jsbin",
"charset": "utf8mb4",
"collate": "utf8mb4_unicode_ci"
}
},
"analytics": {
"id": null,
"render-id": null
},
"ui": {},
"mail": {
"adapter": "sendmail",
"sendmail": {},
"smtp": {
"service": "Gmail",
"auth": {
"user": "",
"pass": ""
}
}
},
"server": {
"logger": "default"
},
"client": {
"user": true
},
"github": {
"id": "",
"secret": ""
},
"notify": {
"errors": [],
"report": []
},
"api": {
"allowAnonymousReadWrite": true,
"allowAnonymousRead": true,
"requireSSL": false
},
"blacklist": {
"html": ["processform.cgi", "habbo.com"],
"css": [],
"javascript": []
},
"reserved": [
"donate",
"list",
"show",
"gist",
"about",
"account",
"accounts",
"activity",
"all",
"announcements",
"api",
"api_rules",
"api_terms",
"apirules",
"apps",
"archive",
"auth",
"badges",
"bin",
"bins",
"blog",
"bugs",
"business",
"contacts",
"collection",
"collections",
"css",
"delete",
"devices",
"download",
"downloads",
"faq",
"favorites",
"favs",
"find_sources",
"find_users",
"followers",
"following",
"fonts",
"font",
"friend_request",
"friendrequest",
"friends",
"goodies",
"help",
"home",
"hooks",
"images",
"img",
"inbox",
"invitations",
"invite",
"issues",
"jobs",
"js",
"last",
"login",
"logout",
"me",
"messages",
"new",
"notifications",
"nudge",
"null",
"open",
"oauth",
"pro",
"profile",
"privacy",
"rules",
"runner",
"scripts",
"search",
"sent",
"settings",
"share",
"signup",
"signin",
"static",
"statistics",
"terms",
"test",
"tos",
"translate",
"trends",
"unarchive",
"user",
"users",
"widgets",
"tutorials",
"video",
"videos",
"-"
]
}

Running JS Bin Locally from fish shell

The [fish shell][] is a very nice shell that works slightly different. In order to run JS Bin locally on needs to execute the following command before the JSBIN_CONFIG variable is picked up correctly

env JSBIN_CONFIG=./config.local.json jsbin

You can find details in the fish shell FAQ.

Errors with npm install -g jsbin

The following command, when run as a super user

npm install -g jsbin

produced the following errors

npm WARN deprecated set-immediate@0.1.1: Use `setimmediate` instead

> sqlite3@2.2.7 install /usr/local/lib/node_modules/jsbin/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

[sqlite3] Command failed: /usr/local/bin/node --eval require('/usr/local/lib/node_modules/jsbin/node_modules/sqlite3/lib/binding/node-v14-darwin-x64/node_sqlite3.node')
dyld: lazy symbol binding failed: Symbol not found: __ZN2v86Object3SetENS_6HandleINS_5ValueEEES3_NS_17PropertyAttributeE
  Referenced from: /usr/local/lib/node_modules/jsbin/node_modules/sqlite3/lib/binding/node-v14-darwin-x64/node_sqlite3.node
  Expected in: dynamic lookup

dyld: Symbol not found: __ZN2v86Object3SetENS_6HandleINS_5ValueEEES3_NS_17PropertyAttributeE
  Referenced from: /usr/local/lib/node_modules/jsbin/node_modules/sqlite3/lib/binding/node-v14-darwin-x64/node_sqlite3.node
  Expected in: dynamic lookup


node-pre-gyp ERR! Testing pre-built binary failed, attempting to source compile
child_process: customFds option is deprecated, use stdio instead.
child_process: customFds option is deprecated, use stdio instead.
  ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlite-autoconf-3080500/sqlite3.c
  TOUCH Release/obj.target/deps/action_before_build.stamp
  CC(target) Release/obj.target/sqlite3/gen/sqlite-autoconf-3080500/sqlite3.o
Release/obj/gen/sqlite-autoconf-3080500/sqlite3.c:8542:26: warning: unused variable 'sqlite3one'
      [-Wunused-const-variable]
SQLITE_PRIVATE const int sqlite3one = 1;
                         ^
1 warning generated.
  LIBTOOL-STATIC Release/sqlite3.a
  CXX(target) Release/obj.target/node_sqlite3/src/database.o
../src/database.cc:134:18: error: no matching member function for call to 'Set'
    args.This()->Set(NanNew("filename"), args[0]->ToString(), ReadOnly);
    ~~~~~~~~~~~~~^~~
/Users/dvberkel/.node-gyp/0.12.0/deps/v8/include/v8.h:2112:8: note: candidate function not viable:
      requires 2 arguments, but 3 were provided
  bool Set(Handle<Value> key, Handle<Value> value);
       ^
/Users/dvberkel/.node-gyp/0.12.0/deps/v8/include/v8.h:2114:8: note: candidate function not viable:
      requires 2 arguments, but 3 were provided
  bool Set(uint32_t index, Handle<Value> value);
       ^
../src/database.cc:135:18: error: no matching member function for call to 'Set'
    args.This()->Set(NanNew("mode"), NanNew<Integer>(mode), ReadOnly);
    ~~~~~~~~~~~~~^~~
/Users/dvberkel/.node-gyp/0.12.0/deps/v8/include/v8.h:2112:8: note: candidate function not viable:
      requires 2 arguments, but 3 were provided
  bool Set(Handle<Value> key, Handle<Value> value);
       ^
/Users/dvberkel/.node-gyp/0.12.0/deps/v8/include/v8.h:2114:8: note: candidate function not viable:
      requires 2 arguments, but 3 were provided
  bool Set(uint32_t index, Handle<Value> value);
       ^
2 errors generated.
make: *** [Release/obj.target/node_sqlite3/src/database.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
gyp ERR! System Darwin 14.3.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--name=sqlite3" "--configuration=Release" "--module_name=node_sqlite3" "--version=2.2.7" "--major=2" "--minor=2" "--patch=7" "--runtime=node" "--node_abi=node-v14" "--platform=darwin" "--target_platform=darwin" "--arch=x64" "--target_arch=x64" "--module_main=./lib/sqlite3" "--host=https://mapbox-node-binary.s3.amazonaws.com/" "--module_path=/usr/local/lib/node_modules/jsbin/node_modules/sqlite3/lib/binding/node-v14-darwin-x64" "--remote_path=./sqlite3/v2.2.7/" "--package_name=node-v14-darwin-x64.tar.gz" "--staged_tarball=build/stage/sqlite3/v2.2.7/node-v14-darwin-x64.tar.gz" "--hosted_path=https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v2.2.7/" "--hosted_tarball=https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v2.2.7/node-v14-darwin-x64.tar.gz"
gyp ERR! cwd /usr/local/lib/node_modules/jsbin/node_modules/sqlite3
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node rebuild --name=sqlite3 --configuration=Release --module_name=node_sqlite3 --version=2.2.7 --major=2 --minor=2 --patch=7 --runtime=node --node_abi=node-v14 --platform=darwin --target_platform=darwin --arch=x64 --target_arch=x64 --module_main=./lib/sqlite3 --host=https://mapbox-node-binary.s3.amazonaws.com/ --module_path=/usr/local/lib/node_modules/jsbin/node_modules/sqlite3/lib/binding/node-v14-darwin-x64 --remote_path=./sqlite3/v2.2.7/ --package_name=node-v14-darwin-x64.tar.gz --staged_tarball=build/stage/sqlite3/v2.2.7/node-v14-darwin-x64.tar.gz --hosted_path=https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v2.2.7/ --hosted_tarball=https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v2.2.7/node-v14-darwin-x64.tar.gz' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/jsbin/node_modules/sqlite3/node_modules/node-pre-gyp/lib/util/compile.js:76:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
node-pre-gyp ERR! stack     at maybeClose (child_process.js:1008:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1080:5)
node-pre-gyp ERR! System Darwin 14.3.0
node-pre-gyp ERR! command "node" "/usr/local/lib/node_modules/jsbin/node_modules/sqlite3/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/jsbin/node_modules/sqlite3
node-pre-gyp ERR! node -v v0.12.0
node-pre-gyp ERR! node-pre-gyp -v v0.5.22
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node rebuild --name=sqlite3 --configuration=Release --module_name=node_sqlite3 --version=2.2.7 --major=2 --minor=2 --patch=7 --runtime=node --node_abi=node-v14 --platform=darwin --target_platform=darwin --arch=x64 --target_arch=x64 --module_main=./lib/sqlite3 --host=https://mapbox-node-binary.s3.amazonaws.com/ --module_path=/usr/local/lib/node_modules/jsbin/node_modules/sqlite3/lib/binding/node-v14-darwin-x64 --remote_path=./sqlite3/v2.2.7/ --package_name=node-v14-darwin-x64.tar.gz --staged_tarball=build/stage/sqlite3/v2.2.7/node-v14-darwin-x64.tar.gz --hosted_path=https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v2.2.7/ --hosted_tarball=https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v2.2.7/node-v14-darwin-x64.tar.gz' (1)
npm ERR! Darwin 14.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--g" "jsbin"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code ELIFECYCLE

npm ERR! sqlite3@2.2.7 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sqlite3@2.2.7 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! This is most likely a problem with the sqlite3 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get their info via:
npm ERR!     npm owner ls sqlite3
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/dvberkel/scratch/projects/analytic-engine/material/npm-debug.log

Known issue

A quick search show that this is a known issue. A possible solution is to downgrade node to 0.10.x

Pre-populate Bins

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.

Feature request

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.

API

The discussion for the feature request mentions the JS Bin API. Furthermore a utility called inliner shows an example how to use the API.

Local JS Bin

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.

npm install -g jsbin

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.

Configuration

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
  }
}

Running

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

Database

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.

Error when cloning a bin

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment