网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網(wǎng)

微信小程序 Node.js (基礎(chǔ)九) 函數(shù) & (基礎(chǔ)十) 路由

發(fā)布時(shí)間:2018-04-21 09:48 所屬欄目:小程序開(kāi)發(fā)教程
微信小程序 Node.js (基礎(chǔ)九) 函數(shù)
 
function say(word){
    console.log(word)
}
function execute(someFunction,value){
    someFunction(value)
}

execute(say,"HelloWorld")
  •  

// 匿名函數(shù)

function execute(someFunction,value){
    someFunction(value)
}
execute(function(word){console.log(word)},"HelloWorld")
  •  
var http = require("http");

function onRequest(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();
}

http.createServer(onRequest).listen(8888);
  •  
 

微信小程序 Node.js (基礎(chǔ)十) 路由

路由:根據(jù)請(qǐng)求的URL和其他需要的GET及POST參數(shù)來(lái)執(zhí)行相應(yīng)的代碼。  我們需要的所有數(shù)據(jù)都會(huì)包含在request對(duì)象中。  為了解析這些數(shù)據(jù),我們需要url和querystring模塊。

                   url.parse(string).query
                                           |
           url.parse(string).pathname      |
                       |                   |
                       |                   |
                     ------ -------------------
http://localhost:8888/start?foo=bar&hello=world
                                ---       -----
                                 |          |
                                 |          |
              querystring.parse(queryString)["foo"]    |
                                            |
                         querystring.parse(queryString)["hello"]
  •  

// 服務(wù)器

//  server.js
var http = require("http")
var url = require("url")

function start(route) {
    function onRequest(request,response){
        var pathname = url.parse(request.url).pathname;
        console.log("pathname:"+ pathname)

        route(pathname)

        response.writeHead(200,{"content-Type":"text/plain"})
        response.write("helloWorld")
        response.end();
    }

    http.createServer(onRequest).listen(8888)
    console.log("程序結(jié)束")
}

// module.exports = start;
exports.start = start
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

// 路由

//  router.js
function route (pathname){
    console.log("About to route a request for:"+pathname)
}

exports.route = route
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
//  main.js
var server = require('./hello')
var router = require('./router')
server.start(router.route)


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開(kāi)源 碼云倉(cāng)庫(kù):starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/23852.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢(xún):800182392 點(diǎn)擊咨詢(xún)
QQ在線(xiàn)咨詢(xún)
AI智能客服 ×