Created
May 17, 2013 05:32
-
-
Save futoase/5597134 to your computer and use it in GitHub Desktop.
YouTubeプレイヤーを利用する時にFlashPlayerからJavaScriptのfunctionをフックするにはローカルじゃあダメってことで
ローカルで静的ファイル配信するの用意した。ありそうだけど。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var http = require('http') | |
| , url = require('url') | |
| , fs = require('fs') | |
| , path = require('path') | |
| , mime = require('mime'); | |
| HTTP_PORT = 8080; | |
| ROOT_REAL_PATH = path.dirname(__filename); | |
| INDEX_FILE_NAME = "index.html"; | |
| http.createServer(function(req, res){ | |
| fs.realpath("." + req.url, function(err, resolvedPath) { | |
| if (err) { console.log( "File not found: " + err ); return; } | |
| fs.exists(resolvedPath, function(exists) { | |
| var contentsPath = resolvedPath; | |
| if (!exists || resolvedPath == ROOT_REAL_PATH) { | |
| contentsPath += '/' + INDEX_FILE_NAME; | |
| } | |
| fs.readFile(contentsPath, function(err, data){ | |
| var type = mime.lookup(contentsPath); | |
| res.writeHead(200, { 'Content-Type': type }); | |
| res.end(data); | |
| }); | |
| }); | |
| }); | |
| }).listen(HTTP_PORT); | |
| console.log('Starting server. post is: ' + HTTP_PORT); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
postとは...