shesite

0.0.0 • Public • Published
Koa middleware framework for nodejs

gitter OpenCollective Sponsors

sheSite是一个快速优雅的建站框架,sheSite基于Node.js框架Koa

环境变量NODE_SITE_CLEAN=delete

koa-static

准备

sheSite安装和运行需要有npm和Node.js。

下载Node.js,安装后命令行有npm命令。

$ npm i sheSite

sheSite是做什么用的

sheSite是一个快速优雅的建站框架

const Koa = require('koa');
const app = new Koa();
 
// response
app.use(ctx => {
  ctx.body = 'Hello Koa';
});
 
app.listen(3000);

用sheSite制作一个简单网站

制作更复杂的网站

MIME

  • Kick-Off-Koa - An intro to Koa via a set of self-guided workshops.
  • Workshop - A workshop to learn the basics of Koa, Express' spiritual successor.

webpack整合

创建package.json,或npm init,然后添加script,恭喜!您的网站就已经建好了:

  • async function
  • common function

注意删除文件夹

建一个网站需要做什么?什么都不用做!

app.use(async (ctx, next) => {
  const start = Date.now();
  await next();
  const ms = Date.now() - start;
  console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});

sheSite的特殊目录

// Middleware normally takes two parameters (ctx, next), ctx is the context for one request,
// next is a function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion.
 
app.use((ctx, next) => {
  const start = Date.now();
  return next().then(() => {
    const ms = Date.now() - start;
    console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
  });
});

配置

  1. 创建一个文件夹。

Old signature middleware support will be removed in v3

Please see the Migration Guide for more information on upgrading from v1.x and using v1.x middleware with v2.x.

加入我们

@目录

app.use(async (ctx, next) => { await next(); });

本地服务器启动 Koa's Request object provides helpful methods for working with http requests which delegate to an IncomingMessage from the node http module.

文件层级的中间件架构

app.use(async (ctx, next) => {
  ctx.assert(ctx.request.accepts('xml'), 406);
  // equivalent to:
  // if (!ctx.request.accepts('xml')) ctx.throw(406);
  await next();
});

访问我的页面。

目录里每一个文件就是一个网址,如/index.html就是http://locaohost/index.html

koa-webpack-dev-middleware

app.use(async (ctx, next) => {
  await next();
  ctx.response.type = 'xml';
  ctx.response.body = fs.createReadStream('really_large.xml');
});

src

For more information on Request, Response and Context, see the Request API Reference, Response API Reference and Context API Reference.

作为静态服务器

外部文件管理

webpack entry

Learn more about the application object in the Application API Reference.

作为node服务器

生产模式

If you're not using node v7.6+, we recommend setting up babel with babel-preset-env:

$ npm install babel-register babel-preset-env --save

koa

require('babel-register');

热更新:

{
  "presets": [
    ["env", {
      "targets": {
        "node": true
      }
    }]
  ]
}

动静结合

Check the Troubleshooting Guide or Debugging Koa in the general Koa guide.

动态路由

$ npm run sheSite

作者

Jeffrey Li

社区

开发模式

创建你的页面。

赞助我们

启动服务器.

cdn发送

你的网站已经可以用了,打开浏览器访问你的页面。

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i shesite

Weekly Downloads

0

Version

0.0.0

License

MIT

Unpacked Size

38.1 kB

Total Files

14

Last publish

Collaborators

  • chfo