Giter Site home page Giter Site logo

casimircore's Introduction

Casimir Core

Build Status Coverage percentage NPM version Dependency Status Slack Channel

js-standard-style

The core modules for the Casimir webapp framework

Install

$ npm i --save casimircore

Features

var casimir_core = require('casimircore')()

console.log(casimir_core)

{
  server: {
    http_server,
    port,
    ssl,
    pub_sub,
    sockets,
    io_server
  },
  Error: 'Error Middleware',
  Router: 'Custom Router with authentication and validation',
  logger: {
    info,
    debug,
    error,
    warn
  },
  properties: properties,
  db: {
    init,
    get_model
  },
  authentication: {
    verify_token,
    verify_specific_user_token,
    check_access,
    issue_token
  },
  block_explorer: {
    get,
    post
  }
}

Authentication

var secret = 'helloKitty'

var callback = function (token, decoded, errmsg, req, res, next) {
  var User = db.get_model('User')
  User.findOne({ user_name: decoded.iss }, function (err, user) {
    if (err) {
      console.warn(err)
      return next(errmsg)
    }
    if (!user) return next()
    if (user.black_list.indexOf(token) !== -1) {
      console.warn('Token has been used')
      return next(errmsg)
    }
    req.user = user
    if (decoded.type === 'api_key') console.log(token, '-', req.path)
    req.user.requestToken = {token: token, decoded: decoded}
    return next()
  })
}

var authentication = casimir_core.authentication(secret, callback)

DB

var mongoose = require('mongoose')
var db = casimir_core.db
var settings = {
  user: 'user',
  pass: 'password',
  host: 'host.mongodb.com',
  port: 27000,
  name: 'testDB',
  dir: './db'
}
db.init(settings, mongoose, function (err, mongoose) {
  if (err) return console.error(err)
  console.log('connected to db')
})

BLOCK-EXPLORER

var block_explorer = casimir_core.block_explorer(explorerURI)

Error

var env = process.env.NODE_ENV
var error = casimir_core.error(env)

Logger

var env = process.env.NODE_ENV
var logentries_api_key = 'fdsfdf23fewfew'

var log_settings = {
  env: env,
  logentries_api_ley: logentries_api_key,
  log_dir: './log'
}

var logger = casimir_core.logger(log_settings)

// Can Actually run over normal console with logger
console.log = logger.info
console.error = logger.error
console.warn = logger.warn
...

Properties

var config_dir = './config'
var properties = casimir_core.properties(config_dir)

RequestId

Router

var GET_public = {
  "/path": {
    "function_name": "File.Function",
    "params": ["param1","param2"],
    "optional": ["optionalParam"],
    "users": ["optionalPrivateUsers"]
  }
}
var contollers_dir = './controllers/'
var routes = {
  GET: { Public: GET_public, Private: GET_private },
  POST: { Public: POST_public, Private: POST_private },
  PUT: { Public: PUT_public, Private: PUT_private },
  DELETE: { Public: DELETE_public, Private: DELETE_private }
}
var router = casimir_core.router(routes, contollers_dir, authentication)

Server

var validator = require('./validator.js')
// Add custom framwork modules for server
properties.modules = {
  validator: validator,
  router: router,
  error: error,
  logger: logger
}
// Set server and server port
var server = casimir_core.server(properties)

Setup

Testing

$ cd /"module-path"/casimircore
$ npm test

License

MIT © thehobbit85

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.