Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "hono", | ||
"version": "0.0.6", | ||
"description": "Minimal web framework for Cloudflare Workers", | ||
"version": "0.0.7", | ||
"description": "Minimal web framework for Cloudflare Workers and Fastly Compute@Edge", | ||
"main": "src/hono.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -6,4 +6,4 @@ # Hono | ||
```js | ||
const Hono = require('Hono') | ||
const app = Hono() | ||
const { Hono } = require('hono') | ||
const app = new Hono() | ||
@@ -10,0 +10,0 @@ app.get('/', () => new Response('Hono!!')) |
@@ -5,3 +5,5 @@ 'use strict' | ||
const compose = require('./compose') | ||
const methods = require('./methods') | ||
const defaultFilter = require('./middleware/defaultFilter') | ||
const Middleware = require('./middleware') | ||
@@ -31,21 +33,18 @@ const METHOD_NAME_OF_ALL = 'ALL' | ||
const proxyHandler = { | ||
get: | ||
(target, prop) => | ||
(...args) => { | ||
if (target.constructor.prototype.hasOwnProperty(prop)) { | ||
return target[prop](...args) | ||
} else { | ||
return target.addRoute(prop, ...args) | ||
} | ||
}, | ||
} | ||
class Hono { | ||
constructor() { | ||
this.router = new Router() | ||
this.middlewareRouter = new Router() | ||
this.middlewareRouters = [] | ||
for (const method of methods) { | ||
this[method] = (...args) => { | ||
return this.addRoute(method, ...args) | ||
} | ||
} | ||
} | ||
all(...args) { | ||
this.addRoute('ALL', ...args) | ||
} | ||
getRouter() { | ||
@@ -62,3 +61,3 @@ return this.router | ||
} | ||
return WrappedApp(this) | ||
return this | ||
} | ||
@@ -68,3 +67,3 @@ | ||
this.router.tempPath = path | ||
return WrappedApp(this) | ||
return this | ||
} | ||
@@ -141,6 +140,8 @@ | ||
const WrappedApp = (hono = new Hono()) => { | ||
return new Proxy(hono, proxyHandler) | ||
} | ||
// Default Export | ||
module.exports = Hono | ||
exports = module.exports | ||
module.exports = WrappedApp | ||
// Named Export | ||
exports.Hono = Hono | ||
exports.Middleware = Middleware |
@@ -1,6 +0,7 @@ | ||
const Hono = require('./hono') | ||
const fetch = require('node-fetch') | ||
const { Hono } = require('./hono') | ||
describe('GET Request', () => { | ||
const app = Hono() | ||
const app = new Hono() | ||
app.get('/hello', () => { | ||
@@ -32,3 +33,3 @@ return new fetch.Response('hello', { | ||
describe('params and query', () => { | ||
const app = Hono() | ||
const app = new Hono() | ||
@@ -64,3 +65,3 @@ app.get('/entry/:id', async (c) => { | ||
describe('Middleware', () => { | ||
const app = Hono() | ||
const app = new Hono() | ||
@@ -67,0 +68,0 @@ const logger = async (c, next) => { |
@@ -1,5 +0,5 @@ | ||
const App = require('./hono') | ||
const { Hono } = require('./hono') | ||
describe('Basic Usage', () => { | ||
const router = App() | ||
const router = new Hono() | ||
@@ -27,3 +27,3 @@ it('get, post hello', async () => { | ||
describe('Complex', () => { | ||
let router = App() | ||
let router = new Hono() | ||
@@ -60,3 +60,3 @@ it('Named Param', async () => { | ||
describe('Chained Route', () => { | ||
let router = App() | ||
let router = new Hono() | ||
@@ -63,0 +63,0 @@ it('Return rooter object', async () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24854
17
675
338
9