我正在使用socket.io從快速應用中獲取一些數據。在localhost:8080上一切正常,但是當我將代碼部署到服務器時,客戶端socket.io無法通過express服務器與後端socket.io進行通信。我有一個服務器上的Apache,將所有內容轉發到localhost:8080,其中包括domain.com/socket.io/?transform=polling ...並將請求擴展到express服務器,但是express將返回404(它來自表達,而不是從apache)。我沒有想法,可能是什麼問題?這裏是我的代碼:socket.io無法通過快遞與後端進行通信
express = require "express"
jade = require "jade"
fs = require "fs"
class Bootstrap
_self = undefined
routes:
DEFAULT_PATH: "/"
TEMPLATE_PATH: "/load/:view"
DIRECTIVE_PATH: "/directive/:template"
options:
templatePath: "#{__dirname}/../src/templates"
isDev: "#{__dirname}/../dev"
contentPath: "#{__dirname}/../frontend"
libraryPath: "#{__dirname}/../bower_components"
port: 8080
status:
notFound: 404
isDev: undefined
constructor: ->
_self = @
@isDev = fs.existsSync @options.isDev
@app = express()
@app.use "/frontend", express.static(@options.contentPath)
@app.use "/bower_components", express.static(@options.libraryPath)
@app.set "views", @options.templatePath
@app.set "view engine", "jade"
@app.engine "jade", jade.__express
@app.get @routes.DEFAULT_PATH, (request, response)->
appData =
data:
isDev: _self.isDev
response.render "index", appData
@app.get @routes.TEMPLATE_PATH, (request, response)->
view = request.param "view"
response.render view
@app.get @routes.DIRECTIVE_PATH, (request, response)->
template = request.param("template").replace ".html", ""
response.render "directives/"+template
@app.use (request, response, next)->
_self.logger.warning "404 Not Found!: " + request.originalUrl
response.status(_self.options.status.notFound)
appData =
data:
isDev : _self.isDev
request: request
response.render "404", appData
@server = @app.listen @options.port
@io = require("socket.io").listen @server
@logger = require("./logger.js")
@logger.init @isDev
@socketConnector = require("./live.js")
@socketConnector.init @io
@
new Bootstrap()
您可以在這裏找到整個代碼:https://github.com/eyurdakul/ejder.be
你能提供apache重寫規則和日誌嗎?你還可以記錄來自該服務器的傳入請求嗎?這將有助於調試問題。 – TheGiantBeast