Saya mencoba membangun server web di node.js yang akan mendukung skrip lintas domain, sambil tetap menyediakan file statis dari direktori publik. Saya menggunakan express.js dan tidak begitu yakin cara mengizinkan skrip lintas domain ( Access-Control-Allow-Origin: *
).
Saya melihat posting ini , yang menurut saya tidak berguna.
var express = require('express')
, app = express.createServer();
app.get('/', function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
app.configure(function () {
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(app.router);
});
app.configure('development', function () {
app.use(express.static(__dirname + '/public'));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function () {
var oneYear = 31557600000;
// app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.static(__dirname + '/public'));
app.use(express.errorHandler());
});
app.listen(8888);
console.log('express running at http://localhost:%d', 8888);