slingshot-ninja

A Slingshot.Ninja module for NodeJS to service Slingshot.Ninja repositiories.

Usage no npm install needed!

<script type="module">
  import slingshotNinja from 'https://cdn.skypack.dev/slingshot-ninja';
</script>

README

slingshot-ninja (a node.js module)

slingshot-ninja is a node.js middleware module for express running on slingshot.ninja repositories. I know there will be at least one person using this middleware... Me!

  • Easy intergration in node.js/express application.
  • Automatic or manual integration of code, views or styles from the repository.
  • Code is subject to changes in the future...

Dependencies

Install

$ express --view=hbs myapp
$ cd myapp
$ npm install slingshot-ninja
$ npm start

Usage

In your app.js file:

var express = require('express');
var autoroute = require('express-autoroute');
var slingshot = require('slingshot-ninja')({
    apiUrl: "https://slingshot.ninja",
    apiKey: "<YOUR-API-KEY>"
});
/* Need a variable that restricts from files 
being overwritten all of the time!*/
let SlingShotNinja = false;
var app = express();
app.use(slingshot, function(req, res, next) {
  req.slingshot.codeParser();
  req.slingshot.loadProject()
  .then(function(projectData) {
    /* Run only once! */
    if (!SlingShotNinja) {
      req.slingshot.pebbleExpress();
      req.slingshot.frameExpress('./routes/', 'server', 'javascript');
      SlingShotNinja = true;
    }
    /* Run always! */
    req.slingshot.keyExpress();
    next();
  }, function(err) {
    console.log(err);
  });
});

autoroute(app, {
  throwErrors: false,
  logger: require('winston'), 
  routesDir: path.join(__dirname, './routes')
});

Some slingshot frame code (frame-name='index' and frame-path='/'):

function index(req, res) {

  req.slingshot.pebbleWrite('index.hbs', 'views/');
  var pf = req.slingshot.pebbleCode('helloworld.js').parseFunction();
  pf(req, res);

}

module.exports.autoroute = {
  get: {
    '/': index
  }
};