2015-10-12 73 views
0

我有這樣的代碼,正在由我的應用程序做一些基本的CRUD和所有的CRUD代碼駐留在customers.js組織快遞JS我的路線

我想有另一個文件media.js提供功能上傳文件和播放多媒體。

我該如何修改我的路線來照顧新文件media.js

這是我的代碼

/** 
* Module dependencies. 
*/ 
var express = require('express'); 
var routes = require('./routes'); 
var http = require('http'); 
var path = require('path'); 
//load customers route 
var customers = require('./routes/customers'); 
var app = express(); 
var connection = require('express-myconnection'); 
var mysql = require('mysql'); 
// all environments 
app.set('port', process.env.PORT || 4300); 
app.set('views', path.join(__dirname, 'views')); 
app.set('view engine', 'ejs'); 
//app.use(express.favicon()); 
app.use(express.logger('dev')); 
app.use(express.json()); 
app.use(express.urlencoded()); 
app.use(express.methodOverride()); 
app.use(express.static(path.join(__dirname, 'public'))); 
// development only 
if ('development' == app.get('env')) { 
    app.use(express.errorHandler()); 
} 
/*------------------------------------------ 
    connection peer, register as middleware 
    type koneksi : single,pool and request 
-------------------------------------------*/ 
app.use(

    connection(mysql,{ 

     host: 'localhost', 
     user: 'root', 
     password : '', 
     port : 3306, //port mysql 
     database:'nodejs' 
    },'request') 
);//route index, hello world 
app.get('/', routes.index);//route customer list 
app.get('/customers', customers.list);//route add customer, get n post 
app.get('/customers/add', customers.add); 
app.post('/customers/add', customers.save);//route delete customer 
app.get('/customers/delete/:id', customers.delete_customer);//edit customer route , get n post 
app.get('/customers/edit/:id', customers.edit); 
app.post('/customers/edit/:id',customers.save_edit); 
app.use(app.router); 
http.createServer(app).listen(app.get('port'), function(){ 
    console.log('Express server listening on port ' + app.get('port')); 
}); 

回答

0

我不知道,如果你有./routes/customers/index.js或./routes/customers.js。

//load customers route 
var customers = require('./routes/customers'); 
//load media route 
var media = require('./routes/media.js'); 
... 
app.get('/media/add', media.add); // You'd need a function defined and exported in your media.js