Socket
Socket
Sign inDemoInstall

casimircore

Package Overview
Dependencies
Maintainers
2
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

casimircore

The core modules for the Casimir webapp framework


Version published
Maintainers
2
Created
Source

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

Authentication

var verify_callback = function (jwt_token, req, res, next) {
  get_user_by_token(jwt_token, function (err, user) {
    if (err) return next(err)
    req.user = user
    next()
  })
}

var access_callback = function (req, res, next) {
  // reaches here if there is no req.user
  res.status(401).send('Not Authorized')
}
 
var authentication = casimir_core.authentication(verify_callback, access_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',

  // with URI - if provided, all previous connection settings are ignored
  uri: 'mongodb://user:password@host.mongodb.com:27000/testDB',

  // mongoose models directory
  dir: './db'
}
db.init(settings, mongoose, function (err, mongoose) {
  if (err) return console.error(err)
  console.log('connected to db')
})

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_key: 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

var settings = {
  secret: 'secret',
  namespace: 'servername'
}
var requestid = casimir_core.request_id(requestSettings)

Router

var fs = require('fs')
var GET_public = {
  "/path": {
    "function_name": "File.Function",
    "params": ["param1","param2"],
    "optional": ["optionalParam"],
    "users": ["optionalPrivateUsers"]
  }
}
fs.writeFileSync(routes_dir + 'GET-public.json', GET_public) // can be similarly done for POST, PUT, DELETE and private
var controllers_dir = './controllers/'
var routes_dir = './routes/'
var router = casimir_core.router(routes_dir, controllers_dir, authentication)

Server

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

Testing

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

License

Apache-2.0

Keywords

FAQs

Package last updated on 29 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc