• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

epii-server: epii-server是基于koa的node应用框架,服务与构建渲染工具分离,提供更 ...

原作者: [db:作者] 来自: 网络 收藏 邀请

epii-server

Build StatusCoverage Status

A koa-based server with preset MVC model.

  • @eggjs/router for controller
  • koa-send for static files
  • access to .well-known
  • koa-bodyparser for body parse & file upload
  • epii-html5 for main document
  • service container (new)

Features

MVC pipeline

(Request)    => / Static /  => / Middleware /  => / Router (Controller) /    => / Render (Model) => (View) /(Response)&/ Service / everywhere

ASP.net-liked

Different ActionResult makes different response.

// service/service1.jsmodule.exports = async ({ context }) => {  // anything you want to provide  return {    example: () => {}  };}// controllermodule.exports = [  {    path: '/',    verb: 'get',    body: async function ({ renders, service1 }) {      // response text/plain      return renders.text('text output');      // response application/json      return renders.json({ state: true });      // response text/html by ViewRender      return renders.view({ name: 'Li Lei' });      // response application/octet-stream      return renders.file('dataset.csv');      // response redirect      return renders.jump('/target');      // use service      return renders.json(service1.example());    }  }];

simple app shell definition

// client/index.meta.jsmodule.exports = {  base: 'simple', // inherit simple layout  head: {    styles: 'client/index.css'  },  body: {    holder: 'client/index.html',    scripts: 'client/index.js'  }};// layout/simple.meta.jsmodule.exports = {  head: {    title: 'epii server',    metas: [],    styles: 'reset.css',    icon: 'epii-icon.png'  },  body: {    scripts: 'jquery-2.2.2.min.js'  }};

Or you maybe want to write HTML directly.

// client/index.meta.jsmodule.exports = {  html: 'client/index.html'}

See also epii-html5.

Usage

project like this

(root)├── [layout]│   └── simple.meta.js├── client│   ├── ViewA│   │   └── index.meta.js│   └── ViewB│       └── index.meta.js├── server│   ├── service│   ├── middleware│   │   └── $order.js│   └── controller│       └── index.js└── static    ├── (files)    └── .well-known        └── (files)

install as dependency

npm install --save @epiijs/server@latest

use API to start server

const { startServer } = require('@epiijs/server');startServer({  name: 'YOUR-APP-NAME',  port: 8080,  path: {    root: __dirname,    server: {      controller: 'server/controller',      middleware: 'server/middleware',      service: 'server/service',    },    client: 'client',    layout: 'layout',    static: 'static',    /* will NEVER support upload */  },  static: {    prefix: '__file',  },  expert: {    'well-known': true, // default false  }});

host server by nginx + certbot

Setup your node app in nginx conf.d directory.

upstream your-app {  server 127.0.0.1:your-port;}server {  listen 80;  server_name your-host;  root /your-app-static-dir;  index index.html;  location / {    proxy_pass http://your-host;    proxy_set_header Host $host;  }}

Use certbot and it will try to validate domain by nginx conf.

FAQ

How to contributing (TODO)

How to serve static files

You can serve your JS + CSS + Media in CDN and use SSR to render app shell html (index.html) with state.The recipe can perform balance between maintainability and performance.

Why not serve index.html in CDN

  1. index.html in CDN can not be updated in real time.
  2. epii-html5 can render index.html very fast.
  3. App shell HTMLs in CDN will work with tedious NGINX or CDN routes.

Language (TODO)


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap