91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Nodejs根據具體請求路徑執行具體操作

發布時間:2020-08-08 01:30:50 來源:網絡 閱讀:1044 作者:素顏豬 欄目:開發技術

1.處理請求模塊(requestHandlers.js)

    function start(){

    console.log("Request handler 'start' was called ");

    return "Hello start";

    }

    

    function upload(){

    console.log("Request handler 'upload' was called ");

    return "Hello Upload";

    }

    

    exports.start = start;

    exports.upload = upload;

2.路由模塊(route.js)

    function route(handle,pathname){

    console.log("About to route a request for "+pathname);

    if (typeof handle[pathname] == 'function') {

    return handle[pathname]();

    }else{

    console.log("No request handler found for " + pathname);

    return "404 Not found";

    }

    }

    

    exports.route = route;

3.服務器模塊(server.js)

    var http = require("http");

    var url = require("url");

    

    function start(route,handle){

    function onRequest(request,response){

    var pathname = url.parse(request.url).pathname;

    if (pathname != "/favicon.ico") {

    console.log("Request for" + pathname + " received");

    response.writeHead(200,{"Content-Type":"text/plain"});

    

    var content = route(handle,pathname);

    response.write(content);

    response.end();

    }

    }

    

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

    console.log("Server has started");

    }

    

    exports.start = start;

4.調用相應模塊(index.js)

    var server = require("./server");

    var router = require("./route");

    var requestHandlers = require("./requestHandlers");

    

    var handle = {};

    handle["/"] = requestHandlers.start;

    handle["/start"] = requestHandlers.start;

    handle["/upload"] = requestHandlers.upload;

    

    server.start(router.route,handle);

5.執行index.js

    node index.js

    訪問:http://localhost:8888/start

    輸出結果:

        Hello start

    訪問:http://localhost:8888/upload

    輸出結果:

        Hello Upload

    訪問:http://localhost:8888/other

    輸出結果:

        404 Not found

Nodejs根據具體請求路徑執行具體操作

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

徐闻县| 桐乡市| 赤城县| 开江县| 内丘县| 滦平县| 阿荣旗| 磐安县| 额尔古纳市| 敦化市| 仙居县| 新疆| 江津市| 沙坪坝区| 青神县| 武隆县| 安平县| 荣昌县| 于田县| 株洲县| 伊宁县| 张家港市| 湄潭县| 山东| 磐石市| 呼玛县| 安阳市| 正阳县| 金川县| 安龙县| 德钦县| 田东县| 梅州市| 太和县| 阿尔山市| 哈巴河县| 洛宁县| 苏尼特左旗| 青海省| 潜江市| 和顺县|