I'm playing with a simple Connect file server:
var connect = require('connect'),
http = require('http');
connect()
.use(connect.static('.'))
.listen(3000);
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);
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?
Try:
var connect = require('connect'),
http = require('http');
connect()
.use(connect.static(__dirname))
.listen(3000);
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.