Created
August 18, 2014 23:19
-
-
Save JScott/e396897ffb61d62e7b99 to your computer and use it in GitHub Desktop.
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
It's a bit ugly but this is close to what I use for the mvml.net server right now to serve MVML. | |
As you can see, it's nothing more than a POST to the server to turn MVML into HTML. | |
Be careful with the lack of error handling in this code. It's very rough. |
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
// MVML API | |
var mvml_server_post = { | |
host: 'http://mvml.net', | |
port: 6865, | |
path: '/', | |
method: 'POST', | |
headers: { | |
'Content-Type': 'text/mvml' | |
} | |
}; | |
function make_request(options, body, callback) { | |
var post_request = http.request(options, function(response) { | |
var response_data = ''; | |
response.on('data', function(data) { | |
response_data += data; | |
}); | |
response.on('end', function() { | |
callback(response_data); | |
}); | |
}); | |
post_request.write(body); | |
post_request.end(); | |
} | |
// Delicious syntax sugar | |
function convert_mvml(mvml_string, callback) { | |
mvml_server_post.headers['Content-Length'] = mvml_string.length; | |
make_request( mvml_server_post, mvml_string, callback ); | |
} | |
function convert_mvml_file(file_path, callback) { | |
fs.readFile(file_path, function(error, data) { | |
if (error) { | |
callback('Error reading MVML file: '+data); | |
} | |
convert_mvml(data, function(html) { | |
callback(html); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment