节点JS Connect文件服务器未按预期运行 [英] Node JS Connect file server not serving as expected
问题描述
我正在使用一个简单的Connect文件服务器:
I'm playing with a simple Connect file server:
var connect = require('connect'),
http = require('http');
connect()
.use(connect.static('.'))
.listen(3000);
文件 index.html
在我加载时访问 localhost:3000
。但是我似乎无法以我期望的方式访问任何其他文件。例如,地址 localhost:3000 / json-parser.html
返回 Error:Forbidden
,后跟有关Connect的信息模块(除非提出要求,否则我不会在此处包括所有内容,因为它很长,我怀疑对此有一个简单的答案)。
The file index.html
loads when I visit localhost:3000
. But I can't seem to access any other file in the way that I would expect. For example, the address localhost:3000/json-parser.html
returns Error: Forbidden
followed by information about the Connect module (I won't include it all here unless requested, because it's quite long and I suspect there is a simple answer to this).
我已经更改了服务器,以下代码此处,以在我的目录中提供公用文件夹:
I have changed my server, following code here, to serve a 'public' folder within my directory:
var connect = require('connect'),
http = require('http');
connect()
.use(connect.static('public'))
.listen(3000);
但是我想访问父目录下文件夹中的脚本和文件公用中的所有内容,并在其外部放置我的Connect文件服务器。鉴于上述方法似乎不起作用,Connect是否有办法在其附近提供目录?
But I want access to scripts and files within folders within the parent directory which isn't possible without putting everything in 'public' and having my Connect file server outside that. Is there a way for Connect to serve the directory around it, given that the above doesn't seem to work?
推荐答案
尝试:
var connect = require('connect'),
http = require('http');
connect()
.use(connect.static(__dirname))
.listen(3000);
但是请记住,这将为服务器运行目录下的所有文件和子目录提供服务。 js,这通常不是一个好计划。
However bear in mind that this will serve ALL the files and subdirectories underneath the directory where you ran server.js which is generally NOT a good plan.
这篇关于节点JS Connect文件服务器未按预期运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!