Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

express 一个奇怪的问题,

$
0
0

app.use(express.static(path.join(__dirname, ‘public’)));//配置的静态文件目录,一开始是可以请求的到里面的html 文件的 但是现在未知原因请求不到了 请求的返回 是the request has no response data avaliable 然后我用了一个特别傻的办法,直接读文件,返回给网页,所以还是想知道express 出了什么问题? ’’‘ var express = require(‘express’) , routes = require(’./routes’) , user = require(’./routes/user’) , http = require(‘http’) , path = require(‘path’) ,fs = require(“fs”) ,register = require(’./lib/router/register’) ;

var app = express(); // all environments app.set(‘port’, process.env.PORT || 3000); app.set(‘views’, __dirname + ‘/views’); app.set(‘view engine’, ‘jade’); app.use(express.favicon()); app.use(express.logger(‘dev’)); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(path.join(__dirname, ‘public’)));

// development only if (‘development’ == app.get(‘env’)) { app.use(express.errorHandler()); }

app.get(’/’, routes.index); app.get(’/users’, user.list); app.get(’/new.html’,function (req,res) { fs.readFile(__dirname+"/public/new.html",“utf8”,function (err,data) { if(err)return console.log(err); res.end(data); }) });

app.use(function(err, req, res, next) { console.error(err.stack); res.status(500).send(‘Something broke!’); });

http.createServer(app).listen(app.get(‘port’), function(){ console.log('Express server listening on port ’ + app.get(‘port’)); });

‘’’


Viewing all articles
Browse latest Browse all 14821

Trending Articles