Project

krtek

0.0
No commit activity in last 3 years
No release in over 3 years
Simple, smart, easy-to-use, fully tested gem
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

 Project Readme

Build Status Code Climate Test Coverage Issue Count

krtek

Krtek

Krtek is a simple node server that allows you to bundle and minify JavaScript on the fly. Krtek can be used as a core of CMS systems or for applications that require dynamic code compilation. Krtek has built in support for ES2015 and React JSX. Krtek uses file caching by default, but you can also implement your own caching provider very easily.

⚠️ WARNING Krtek can be evil 👺, because eval() is evil. Krtek doesn't use eval(), but it accepts JavaScript code as a string, so it can possibly open a gate to your server for hackers! In order to reduce the risk of being hacked make sure all code that is coming from unknown source is executed in the sandbox (you can use for example: vm.runInContext or sandbox). It's also good idea to encrypt the JavaScript code in the browser and decrypt it on krtek server (see. CryptoJS) using some secret key. Just make sure that you have a really good reason before you start using Krtek and also be aware of security risks!

Instalation

Yarn

yarn add krtek

npm

npm i krtek -S

Usage

import Krtek from 'krtek';

const krtek = new Krtek();

krtek.on('start', () => {
  console.log(
    `Krtek is running on ${krtek.host}:${krtek.port}`
  );
});

krtek.app.get('/magic', (req, res) => {
  krtek.bundle(req, res);
});

krtek.on('bundle', (req) => {
  krtek.setJsCode(`
    import React from 'react';
    import { render } from 'react-dom';

    import { Hello } from './components';

    render(${req.query.js}, document.getElementById("${req.query.id}"));
  `);
});

krtek.on('done', (req, res, data) => {
  res.write(data);
  res.end();
});

krtek.on('error', (req, res, error) => {
  res.write(error);
  res.end();
});

krtek.start();

Now navigate to localhost:3000/magic?id=app&js=<Hello /> and you will get a bundled JavaScript that will render Hello component in your div#app.

Copyright © 2016 Jiri Chara. All Rights Reserved.