0
我有一個socket.io項目,但它不讓我使用公用文件夾。我想啓動該hello.jsexpress.static在node.js項目中不起作用
http://i.stack.imgur.com/ugDZw.png
但我只看到
http://i.stack.imgur.com/fZhjJ.png
我什麼都試過,只是重新安裝的node.js
var express = require('express');
var app = express();
var http = require("http");
var io = require('socket.io');
var url = require('url');
var fs = require('fs');
app.use(express.static(__dirname + '/public'));
var server = http.createServer(function(request, response){
console.log('Connection');
var path = url.parse(request.url).pathname;
switch(path){
case '/':
response.writeHead(200, {'Content-Type': 'text/html'});
response.write('hello world');
response.end();
break;
case '/socket.html':
fs.readFile(__dirname + path, function(error, data){
if (error){
response.writeHead(404);
response.write("opps this doesn't exist - 404");
}
else{
response.writeHead(200, {"Content-Type": "text/html"});
response.write(data, "utf8");
}
response.end();
});
break;
default:
response.writeHead(404);
response.write("opps this doesn't exist - 404");
response.end();
break;
}
});
server.listen(8001);