https://github.com/ymzuiku/nature-http
一个非常自然的 web 框架 没有任何黑魔法,源码仅有 250 行,纯粹的 nodejs 原生 http 库
https://github.com/ymzuiku/nature-http
Last synced: about 2 months ago
JSON representation
一个非常自然的 web 框架 没有任何黑魔法,源码仅有 250 行,纯粹的 nodejs 原生 http 库
- Host: GitHub
- URL: https://github.com/ymzuiku/nature-http
- Owner: ymzuiku
- Created: 2018-08-29T15:15:27.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-13T17:06:22.000Z (over 6 years ago)
- Last Synced: 2025-03-12T20:37:43.118Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 222 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nature
一个非常自然的 web 框架
没有任何黑魔法,源码仅有 250 行,纯粹的 nodejs 原生 http 库,为了性能没有使用 async。
## 使用例子
```js
const nature = require('nature-http');
const staticPath = nature.resolve(process.cwd(), './example/public/');// nature.pages['404'] = '/api/test?bbb=222';
const schema = `
type Query {
hello: String
}
`;nature.listenThreads(4100, ctx => {
ctx.get('/api/get', data => {
ctx.res.end(JSON.stringify(data));
});
ctx.post('/api/post', data => {
console.log(data);
ctx.res.end(JSON.stringify(data));
});
ctx.graph('/graphql', schema, {
hello: () => 'hello, graphql',
});
ctx.static(nature.resolve(staticPath));
});
```