Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var host = '192.168.2.3';
- var PORT = 8051;
- function main() {
- // Get path, so that #CDN# can be replaced with the actual URL
- // Found path, create server
- require('http').createServer(function(request, response) {
- console.log(request.url, request.headers);
- // (CORS) headers
- var headers={
- "Access-Control-Allow-Origin": request.headers.origin || '*',
- "Access-Control-Allow-Methods": "GET",
- "Access-Control-Allow-Credentials": "true"
- };
- var r = response.writeHead;
- response.writeHead=function() {
- console.log('----------------RES-------')
- console.log(arguments);
- console.log('--------------------------')
- return r.apply(this, arguments);
- };
- if (request.method === 'OPTIONS') {
- headers['Access-Control-Allow-Headers'] = 'X-Requested-With, Location';
- }
- if (request.method == 'OPTIONS') {
- response.writeHead(200, headers);
- response.end();
- return;
- }
- if (request.url === '/redir') {
- response.writeHead(204, headers);
- response.end();
- return;
- }
- headers["Location"] = 'http://' + host + ':' + PORT + '/redir';
- response.writeHead(302, headers);
- response.end();
- }).listen(PORT);
- console.log('Listening on http://' + host + ':' + PORT + '/.');
- return 0;
- }
- // When run from shell, start server.
- // When included from a different module, export
- if (require.main === module) {
- main();
- } else {
- exports.startServer = main;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement