0
我有这个程序:斯普利特快递应用
// Some modules
var express = require("express");
var ... = require("...");
var ... = require("...");
// Here will go the db
var db;
// Init express
var app = express();
// Express configuration
app.use(...);
app.use(...);
// Routes
app.get("/", function() {});
app.get("/api/v1/a", function() {});
app.get("/api/v1/b", function() {});
// Connect to the db, store it in "db" and then set the port of the app
MongoClient.connect("mongodb://localhost/db", function(err, connection) {
db = connection;
app.listen(3000);
});
我想分裂这个应用程序在多个文件,比如我想路线移动API为api.js
文件。
我试过这个api.js
:
function(app, db) {
app.get("/api/v1/a", function() {});
app.get("/api/v1/b", function() {});
}
module.exports = api;
再搭配使用:
var api = require("./api");
api(app, db);
但里面所定义的路由不执行,我该怎么办?
它永远挂起。 – 2014-09-12 16:37:15