From b9ff21d1de0f15bfede85bb566382844036610a4 Mon Sep 17 00:00:00 2001 From: Ethan Davis Date: Sat, 30 Sep 2017 17:36:09 -0700 Subject: [PATCH] 1.0.0 Preparation: Initial Additions --- .gitignore | 48 ++++++++++++++++++++++++++++++++++++++++++++++ .npmignore | 20 +++++++++++++++++++ .travis.yml | 6 ++++++ LICENSE.md | 7 +++++++ README.md | 28 ++++++++++++++++++++++++++- lib/Vaxic.js | 37 +++++++++++++++++++++++++++++++++++ lib/VaxicServer.js | 27 ++++++++++++++++++++++++++ package.json | 27 ++++++++++++++++++++++++++ 8 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 .travis.yml create mode 100644 LICENSE.md create mode 100644 lib/Vaxic.js create mode 100644 lib/VaxicServer.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a9ee18 --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +.eslintrc.json +.DS_Store +*.tgz + +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Only dev-dependencies +package-lock.json + +# Env information / sensitive data +.env +pids +*.pid +*.seed +*.pid.lock +sftp-config.json + +# Don't include dep directories. +node_modules/ +jspm_packages/ + +# NPM cache +.npm + +# Node REPL history +.node_repl_history + +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +*.sublime-workspace + +# Sublime Package Control files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..ee196a7 --- /dev/null +++ b/.npmignore @@ -0,0 +1,20 @@ +# NPM, Yarn, Travis ignores + +.eslintrc.json +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pids +*.pid +*.seed +*.pid.lock +.npm +*.tgz +.travis.yml + +# Core resource ignores + +docs/ +media/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..32b3976 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "node" + - "8" + - "7" + - "6" \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..99e9be6 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,7 @@ +License information: https://github.com/omnent/omnent-licenses/blob/master/licenses/OMv2-FO.txt + +Copyright 2017 Ethan Davis + +Permission is hereby granted, for free, to any person obtaining a copy of this software and associated documentation files (collectively "the Software" or "THE SOFTWARE"), to (without restriction) use, modify, copy, publish, execute, distribute, sublicense, and sell the Software and to allow people who gain access to the Software to do the same as long as this entire license and the above copyright notice are included in all copies or portions of the Software. + +NOTWITHSTANDING ANYTHING IN CONTRADICTION, THE AUTHORS AND COPYRIGHT HOLDERS OF THE SOFTWARE SHALL UNDER NO CIRCUMSTANCES BE HELD LIABLE FOR ANY DAMAGES, CLAIM, OR OTHER LIABILITY RELATED TO, IN CONNECTION WITH, OR CAUSED BY USE OR DISTRIBUTION OF THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS-IS" AND IS NOT PROVIDED WITH WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, AND ANY WARRANTY ARISING OUR OF PRIOR COURSE OF DEALING AND USAGE OF TRADE. \ No newline at end of file diff --git a/README.md b/README.md index d85cd5d..e00fb5b 100644 --- a/README.md +++ b/README.md @@ -1 +1,27 @@ -# vaxic \ No newline at end of file +

vaxic logo

+ +--- + +> The ultra-light superpower Node web framework + +[Full documentation](https://ethanent.github.io/vaxic/) | [GitHub](https://github.com/ethanent/vaxic) | [NPM](https://www.npmjs.com/package/vaxic) + +## Install + +```shell +npm install --save vaxic +``` + +## Basic usage + +```javascript +const Vaxic = require('vaxic') + +const app = new Vaxic() + +app.add('GET', '/getEndpoint', (req, res) => { + res.writeHead(200) + res.end('Hello.') +}) +``` + diff --git a/lib/Vaxic.js b/lib/Vaxic.js new file mode 100644 index 0000000..9358ca5 --- /dev/null +++ b/lib/Vaxic.js @@ -0,0 +1,37 @@ +const path = require('path') +const http = require('http') +const VaxicServer = require(path.join(__dirname, 'VaxicServer.js')) + +class Vaxic extends VaxicServer { + constructor () { + super() + + this.internalServer = http.createServer(this.serverHandler) + } + + add (a1, a2, a3) { + const handler = { + 'type': 'rule', + 'target': { + 'method': (a3 ? a1 : null), + 'url': (a3 ? a2 : a1), + }, + 'handler': (a3 || a2) + } + + this.handlers.push(handler) + } + + use (midhandler) { + const handler = { + 'type': 'mid', + 'handler': midhandler + } + + this.handlers.push(handler) + } + + listen (port, host, cb) { + this.internalServer.listen(port, host, (cb || null)) + } +} \ No newline at end of file diff --git a/lib/VaxicServer.js b/lib/VaxicServer.js new file mode 100644 index 0000000..80a9740 --- /dev/null +++ b/lib/VaxicServer.js @@ -0,0 +1,27 @@ +class VaxicServer { + constructor (handlers) { + this.handlers = handlers || [] + } + + serverHandler (req, res) { + for (let i = 0; i < handlers.length; i++) { + if (handlers[i].type === 'rule') { + const rules = handlers[i].target + + if (rules.method ? (rules.method !== req.method) : false) continue + + if (rules.url ? (rules.url instanceof RegExp ? !rules.url.test(req.url) : (res.url.indexOf('*') === res.url.length - 1 ? res.url.indexOf(rules.url) !== 0 : res.url !== rules.url)) : false) continue + + handlers[i].handler(req, res) + } + else if (handlers[i].type === 'mid') { + handlers[i].handler(req, res, () => { + continue + }) + break + } + } + } +} + +module.exports = VaxicServer \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..00561ed --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "vaxic", + "version": "1.0.0", + "description": "The lightweight, flexible web framework", + "main": "lib/Vaxic.js", + "scripts": { + "test": "node test/test.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ethanent/vaxic.git" + }, + "keywords": [ + "web", + "api", + "app", + "webapp", + "vaxic", + "http" + ], + "author": "Ethan Davis", + "license": "SEE LICENSE IN LICENSE.md", + "bugs": { + "url": "https://github.com/ethanent/vaxic/issues" + }, + "homepage": "https://github.com/ethanent/vaxic#readme" +}