Skip to content

Instantly share code, notes, and snippets.

@evantahler
Created June 5, 2013 03:22
Show Gist options
  • Save evantahler/5711399 to your computer and use it in GitHub Desktop.
Save evantahler/5711399 to your computer and use it in GitHub Desktop.
Using an actionHero action to send a static file (perhaps for a single page app using pushState)
exports.action = {
name: "fileResponder",
description: "fileResponder",
outputExample: {},
inputs: { required: [], optional: [] },
run: function(api, connection, next){
var server = api.servers.servers[connection.type];
try{
// the hard-coded file you want to send, relitive to site's root
connection.params.file = "index.html"
server.processFile(connection);
// no callback needed.
}catch(e){
console.log(e)
connection.error = "Your connection type, `" + connection.type + "`, can not be sent files";
next(connection, true);
}
}
};
@evantahler
Copy link
Author

Current as of actionHero version 6.x

@evantahler
Copy link
Author

These days, you really should call the next() callback in your action
however, you can set data.toRender = false to ensure nothing other than the file is sent to the client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment