我试过 localhost:3000/index.html (我放静态页面的地方), localhost:3000/javascripts/dio.js (我放 js 的地方) localhost:3000/images/dio1.jpg (我放图片的地方),全部无法访问。为什么?怎么了?
我的 app.js 定义:
var express = require('express')
var app=express()
app.bcrypt = require('bcrypt')
app.im=require('imagemagick')
app.fs=require('fs')
app.application_root = __dirname
app.path = require("path")
app.mongoose = require("mongoose")
var config=require('./config.js')(app,express)
var models = require('./models/models.js')(app.mongoose)
models.UserModel = models.UserModel
models.CommentModel = models.CommentModel
models.ItemModel = models.ItemModel
require('./routes')(app, models)
app.listen(3000);
console.log("Listening on port 3000")
这是我的 config.js 定义:
module.exports = function(app, express, mongoose){
var config=this
app.configure(function (){
app.set('views',__dirname+'/views')
app.set('view engine','jade')
app.set('view engine', {layout:true})
app.use(express.bodyParser())
app.use(express.methodOverride())
app.use(express.cookieParser())
app.use(express.session({secret: 'topsecret',store: new express.session.MemoryStore}))
app.use(app.router)
app.use(express.static(app.path.join(app.application_root+"public")))
app.use(express.errorHandler({dumpExceptions:true,showStack:true}))
app.use(express.bodyParser({keepExtensions: true, uploadDir:"./public/uploads"}))
})
/*DB part:*/
app.mongoose.connect('mongodb://localhost/dio_database')
return config
}