Code Monkey home page Code Monkey logo

easyserver.js's Introduction

简单的服务器

EasyServer.js logo

继承自express的简单服务器,不需要为路由而烦恼

目录约束

config目录(必须)

  • 该目录是config模块自动加载,根据NODE_ENV进行主动加载对应的.js or .json文件
  • 不管NODE_ENV是什么,默认加载default.js or default.json
  • default.js 默认应有内容
    • "rootPath": '' 这是给框架提供项目根目录 (默认已有,如不必须,不用写该参数)
    • "port":9889 项目启动端口号

routes(路由目录,必须,重要!!!!!请仔细阅读)

views(渲染文件目录,必须)

  • views目录下有且仅有html文件
  • routes目录下.js文件display方法,默认无参数时,访问的是/views/1级路由.html
    • 举例 http://domain/user/index 如果indexAction中执行了display()方法,那么渲染的就是/views/user.html
    • 举例 http://domain/user/index 如果indexAction中执行了display("index.html")方法,那么渲染的就是/views/index.html
    • 举例 http://domain/user/index 如果indexAction中执行了display("/lib/index.html")方法,那么渲染的就是/views/lib/index.html

static(静态资源目录)

  • 该目录下可以存放任何东西,可以通过http://domain/static/xxx.xxx 直接访问
  • views目录下的html文件,里面如果使用静态文件,比如图片,比如js等,看下面示例
    • 图片:
    • JS文件:<script src='/static/1.js'>
    • 注意,静态文件的起始目录永远为'/static'

API

EasyServer

  • start()方法 启动服务器,默认端口是9889

Router(此类应为被继承类,建议不要直接使用)

  • before()方法,请求进入该对象后,第一个执行的方法,返回FALSE,即立即结束后续操作
  • xxxAction()子类自定义方法,使用方式如下
    • http://domain/user/index/getUser 请求的路由地址为 /routes/user/index.js 下的getUserAction()方法
    • 该方法返回false,即立即结束后续操作
    • 该方法应都为post请求
    • xxx应全部为小写,因为浏览器地址栏不支持大写
  • __call() 方法,如果请求路由没有击中任何xxxAction()方法,那么默认执行该方法,返回false,即立即结束后续操作
  • after()方法,最后执行方法

安装方式

npm install easyserver.js -S

import {EasyServer,Router} from 'EasyServer'
let server = new EasyServer();
server.start();

Licence

MIT

easyserver.js's People

Contributors

332065255 avatar foxdaxian avatar

Stargazers

Athon avatar  avatar xuān avatar xtqqqqdx avatar  avatar

Watchers

James Cloos avatar  avatar

easyserver.js's Issues

研发规划

  • [优化路由系统 ]

  • [get,post区分 ]

  • [支持.html文件下发 ]

  • [编写easyServer-generator ]

  • [支持middleware ]

  • [日志系统??]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.