我想知道是否可以使用Node.js开发一个便携式聊天应用程序。
我的意思是,如果有一个提供Node.js聊天服务的中央网站,用户可以获取脚本代码(不管是基于JavaScript还是iframe),并将聊天程序发布到他们的网站上。
假设此应用程序托管在chatServer.com上
例如,如果用户有一个div,其ID为适当的表单输入,并且已将chatServer.com中的一个脚本链接起来。
或
)
或
如果我没记错的话,JSON数据不能跨不同的域进行交易。
你认为这是可能的申请吗?
我只想知道是否有可能建造它。
我见过一些类似的web聊天应用程序,它们是用'Python twisted'+'swf‘实现的。
发布于 2011-09-19 21:13:01
如果您使用socket.io,它将简单地使用jsonp进行跨域通信。
<script src="//chatServer.com/socket.io.js"></script>
<script>
var socket = io.connect('//chatServer.com');
socket.on('chat', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>发布于 2016-04-12 07:39:41
我面临跨域问题,我的app.js代码是
var express = require('express'),
app = express();
var port = process.env.PORT || 8080;
// Initialize a new socket.io object. It is bound to
// the express app, which allows them to coexist.
var io = require('socket.io').listen(app.listen(port));
// Require the configuration and the routes files, and pass
// the app and io as arguments to the returned functions.
io.use(function(socket, next) {
var handshakeData = socket.request;
//console.log(handshakeData);
next();
});
// Require the configuration and the routes files, and pass
// the app and io as arguments to the returned functions.
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods", "GET,POST");
next();
});
require('./config')(app, io);
require('./routes')(app, io);
console.log('Your application is running on http://localhost:' + port);https://stackoverflow.com/questions/7476542
复制相似问题