2016-07-09 2 views

答えて

2

簡潔に:消費者が必要とするハンドラ関数を公開します。app.use()

ここに一般的なアプローチがあります。消費者の観点から、今

module.exports = function myExtension() { 
    return function myExtensionHandler(req, res, next) { 
    // This is called for every request - you can extend req or res here 
    req.myFun = myFun 

    // Make sure to call next() in order to continue the 
    // chain of handlers 
    return next() 
    } 
} 

function myFun() { 
    // My magic function 
} 

:次のモジュールを考えてみ

const express = require('express') 
const myExtension = require('my-extension') 
const app = express() 

// Here you tell Express to use your extension for incoming requests 
app.use(myExtension()) 
// ... 
関連する問題