Skip to content

Instantly share code, notes, and snippets.

@JScott
Created August 18, 2014 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JScott/e396897ffb61d62e7b99 to your computer and use it in GitHub Desktop.
Save JScott/e396897ffb61d62e7b99 to your computer and use it in GitHub Desktop.
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.
// 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