Created
June 5, 2013 03:22
-
-
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)
This file contains 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
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); | |
} | |
} | |
}; |
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
Current as of actionHero version 6.x