diff --git a/bin/thinkjs b/bin/thinkjs index 27470060..7a950c2e 100755 --- a/bin/thinkjs +++ b/bin/thinkjs @@ -26,6 +26,7 @@ var content = [ 'global.APP_PATH = __dirname + "/../App";', '//静态资源根目录', 'global.RESOURCE_PATH = __dirname;', + 'global.ROOT_PATH = __dirname;', 'global.APP_DEBUG = true;', 'require("thinkjs");' ].join("\n"); diff --git a/web/App/Conf/config.js b/web/App/Conf/config.js index 9006796c..3d9ddea9 100644 --- a/web/App/Conf/config.js +++ b/web/App/Conf/config.js @@ -1,3 +1,4 @@ module.exports = { + port: 9876 //配置项: 配置值 } \ No newline at end of file diff --git a/web/App/Conf/route.js b/web/App/Conf/route.js new file mode 100644 index 00000000..9a14cb62 --- /dev/null +++ b/web/App/Conf/route.js @@ -0,0 +1,3 @@ +module.exports = [ + [/^(.*)$/, "index/doc?doc=:1"] +] \ No newline at end of file diff --git a/web/App/Conf/tag.js b/web/App/Conf/tag.js new file mode 100644 index 00000000..e69de29b diff --git a/web/App/Lib/Controller/Home/IndexController.js b/web/App/Lib/Controller/Home/IndexController.js index 93ef8e86..382f32bf 100644 --- a/web/App/Lib/Controller/Home/IndexController.js +++ b/web/App/Lib/Controller/Home/IndexController.js @@ -5,8 +5,15 @@ module.exports = Controller(function(){ return { indexAction: function(){ - //render View/Home/index_index.html file - this.display(); + this.display("index:index"); + }, + docAction: function(doc){ + var viewFile = VIEW_PATH + "/Home/doc_" + doc + ".html"; + if (isFile(viewFile)) { + this.display("doc:" + doc); + }else{ + this.display("index:index"); + } } } }); \ No newline at end of file diff --git a/web/App/View/Home/doc_api.html b/web/App/View/Home/doc_api.html new file mode 100644 index 00000000..1e5ab5bf --- /dev/null +++ b/web/App/View/Home/doc_api.html @@ -0,0 +1,180 @@ +<% include inc/header.html %> +
+
+

原生对象的扩展

+

Object.values(obj)

+ +

获取对象值的集合

+ +

Array.prototype.sum

+ +

获取数组的和

+ +

全局函数

+

Class

+

extend

+

isBoolean

+

isNumber

+

isObject

+

isString

+

isFunction

+

isDate

+

isRegexp

+

isError

+

isEmpty

+

isArray

+

isIP

+

isIP4

+

isIP6

+

isFile

+

isDir

+

isBuffer

+

isPromise

+

isWritable

+

mkdir

+

chmod

+

getFileContent

+

setFileContent

+

ucfirst

+

md5

+

getPromise

+

getDefer

+

getObject

+ +

thinkRequire

+

inherits

+

Cache

+

Behavior

+

Controller

+

Session

+

Model

+

Db

+

B

+

tag

+

C

+

A

+

F

+

D

+

S

+

E

+ +

Controller类的方法

+ +

controller.ip()

+ +

获取当前用户的ip

+ +

controller.isGet()

+ +

是否为GET请求

+ +

controller.isPost()

+ +

是否为POST请求

+ +

controller.isMethod(method)

+ +

判断当前请求类型与传递的参数是否相同

+ +

controller.isAjax()

+ +

是否为ajax请求

+ +

controller.get(name)

+ +

获取get参数的值,如果name为undefined,则返回所有的参数值

+ +

controller.post(name)

+ +

获取POST参数的值,如果name为undefined,则返回所有的POST值

+ +

controller.param(name)

+ +

获取POST或者GET参数的值(优先从POST里获取),如果name为undefined,则返回所有的值

+ +

controller.file(name)

+ +

获取上传的文件对象

+ +

controller.header(name, value)

+

获取或者设置header

+ + +

controller.userAgent()

+ +

返回用户的userAgent

+ +

controller.referrer()

+ +

返回当前请求的referrer

+ +

controller.cookie(name, value, options)

+ +

controller.session(name, value)

+ +

controller.redirect(url, code)

+ +

controller.assign(name, value)

+ +

controller.fetch(templateFile, content)

+ +

controller.display(templateFile, charset, contentType, content)

+ +

controller.action(action)

+ +

controller.jsonp(data)

+ +

controller.json(data)

+ +

controller.status(status)

+ +

controller.echo(obj, encoding)

+ +

controller.end(obj)

+ +

controller.download(file, contentType)

+ +

controller.success(data)

+ +

controller.error(data)

+ +

Model类的方法

+
+
\ No newline at end of file diff --git a/web/App/View/Home/doc_guide.html b/web/App/View/Home/doc_guide.html new file mode 100644 index 00000000..11a0d808 --- /dev/null +++ b/web/App/View/Home/doc_guide.html @@ -0,0 +1,58 @@ +<% include inc/header.html %> +
+
+ +

安装

+
sudo npm install -g thinkjs
+ +

创建项目

+
mkdir path/to/xxx;
+cd path/to/xxx;
+thinkjs .
+

执行后,如果当前环境有浏览器,会自动用浏览器打开 http://127.0.0.1:8360,并且会看到如下的内容

+
hello, thinkjs!
+ +

项目结构

+
.
+├── App
+│   ├── Common
+│   │   └── common.js    ---- 通用函数文件,一般将项目里的一些全局函数放在这里
+│   ├── Conf
+│   │   └── config.js    ---- 项目配置文件
+│   ├── Lib
+│   │   ├── Behavior     ---- 行为类存放位置
+│   │   ├── Controller
+│   │   │   └── Home
+│   │   │       └── IndexController.js   ---- 逻辑控制类
+│   │   └── Model        ---- 模型类
+│   ├── Runtime          ---- 运行时的一些文件
+│   │   ├── Cache        ---- 缓存目录
+│   │   ├── Data         ---- 数据目录
+│   │   ├── Log
+│   │   └── Temp
+│   └── View
+│       └── Home
+│           └── index_index.html      ---- 模版文件,默认使用ejs模版引擎
+├── ctrl.sh              ---- 项目启动、停止脚本
+└── www
+    ├── index.js         ---- 入口文件
+    └── resource         ---- 静态资源目录
+        ├── css
+        ├── img
+        ├── js
+        ├── module
+        └── swf
+ +

模版引擎

+

Think.js默认使用的是ejs模版引擎,你可以从这里查看ejs的具体使用方法。

+

修改App/View/Home/index_index.html页面,保存后刷新页面,即可看到修改后的内容。

+ +

开发模式

+

Think.js默认为debug开发模式,这种模式下修改当前项目下的任意文件,刷新页面后即可看到效果,不需要重启Node.js服务。

+

代码上线时需要将www/index.js里的global.APP_DEBUG = true;设置为false,从而提高性能。

+ +

启动/关闭Node.js服务

+

开发环境下建议通过cd www; node index.js来启动服务。

+

线上环境可以通过sh ctrl.sh start/restart/stop命令来启动/重启/关闭服务。

+
+
\ No newline at end of file diff --git a/web/App/View/Home/doc_intro.html b/web/App/View/Home/doc_intro.html new file mode 100644 index 00000000..851a8c60 --- /dev/null +++ b/web/App/View/Home/doc_intro.html @@ -0,0 +1,6 @@ +<% include inc/header.html %> +
+
+

介绍

+
+
\ No newline at end of file diff --git a/web/App/View/Home/inc/header.html b/web/App/View/Home/inc/header.html new file mode 100644 index 00000000..0ad481c2 --- /dev/null +++ b/web/App/View/Home/inc/header.html @@ -0,0 +1,44 @@ + + + + + + + thinkjs官方网站 + + + + + + + + + + \ No newline at end of file diff --git a/web/App/View/Home/index_index.html b/web/App/View/Home/index_index.html index 292ab0ed..7bf30089 100644 --- a/web/App/View/Home/index_index.html +++ b/web/App/View/Home/index_index.html @@ -1,69 +1,43 @@ - - - - - - - - thinkjs官方网站 - - - - - - - - - - +<% include inc/header.html %>
-

node.js web application framework

-

thinkjs是一个快速、简单的基于MVC和面向对象的轻量级node.js开发框架,遵循MIT协议发布。秉承简洁易用的设计原则,在保持出色的性能和至简的代码同时,注重开发体验和易用性,为WEB应用开发提供强有力的支持。

+

A Node.js Web Application Framework

+

Think.js是一个快速、简单的基于MVC和面向对象的轻量级Node.js开发框架,遵循MIT协议发布。秉承简洁易用的设计原则,在保持出色的性能和至简的代码同时,注重开发体验和易用性,为WEB应用开发提供强有力的支持。

+

Think.js里面很多特性来源于ThinkPHP,同时根据Node.js的特点,使用了Promise, WebSocket等特性,让代码更简洁、优雅。

查看更多 »

-
-

解决的问题

+
+

开发者

+
+
+

Changelog

+
    +
  • 优化Session机制,实现gc
  • +
  • 支持websocket,无缝切换
  • +
+
+
+

已经使用的产品

+ -

查看更多 »