> curl localhost:8080/simple.html -v
* Trying ::1..
* connect to ::1 port 8080 failed: Connection refused
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080
> GET /simple.html HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Last-Modified: Fri Jun 12 2015 02:51:29 GMT-0700 (PDT)
< Cache-Control: max-age=60, must-revalidate, public
< Expires: Sun, 15 Nov 2015 02:07:46 GMT
< Content-Type: text/html
< Access-Control-Allow-Headers: Content-Type
< Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE
< Access-Control-Allow-Origin: *
< X-Powered-By: Actionhero API
< Set-Cookie: sessionID=d4453f54ff066a2ef078e5c80f18dc78a81f44ff;path=/;expires=Sun, 15 Nov 2015 03:06:46 GMT;
< Content-Length: 101
< Date: Sun, 15 Nov 2015 02:06:46 GMT
< Connection: keep-alive
<
* Connection #0 to host localhost left intact
<h1>Actionhero</h1>\nI am a flat file being served to you via the API from ./public/simple.html<br />
Actionhero comes with a file server which clients can make use of to request files from the Actionhero server. Actionhero is not meant to be a 'rendering' server, but can serve static files.
If a directory is requested rather than a file, Actionhero will look for the file in that directory defined by config.commonWeb.directoryFileType
(which defaults to index.html
). Failing to find this file, an error will be returned defined in config.general.flatFileIndexPageNotFoundMessage
You can use the await staticFile.get(connection)
in your actions (where the response object contains error
, fileStream
, mime
, and length
). Note that fileStream is a stream which can be pipe'd to a client. You can use this in actions if you wish.
On unix/OSX operating systems, symlinks for both files and folders will be followed.
Cache-Control
and Expires
or respectively ETag
headers (depending on configuration) will be sent with it's caching or revalidation time defined by config.web.flatFileCacheDuration
connection.params.file
directly within an action which makes use of api.sendFile
, or if they are under the config.web.urlPathForFiles
route, the file will be looked up as if the route matches the directory structure under flatFileDirectory
.file
should be used to request a pathfile.content
's data is sent raw
, and is likely to contain binary content and line breaks. Parse your responses accordingly!// send a file
async run (data) {
data.connection.sendFile('/path/to/file.mp3')
data.toRender = false
}
// send 404 (web connection)
async run (data) {
data.connection.rawConnection.responseHttpCode = 404;
data.connection.sendFile('404.html')
data.toRender = false
}
You can send files from within actions using connection.sendFile()
.
Note that you can optionally modify responseCodes (for HTTP clients only). Be sure to set toRender = false
in the callback, as you have already sent data to the client, and probably don't want to do so again on a file request. If you try to sendFile
on a path that doesn't exist (within your public directory), the 404 header will be handled automatically for you.
Actionhero will check all paths defined by config.general.paths.public
for files, in the order they are specified via that option, then check any public paths of your plugins. Actionhero's file server will not serve files outside of the directories enumerated by config.general.paths.public
for security.
The Actionhero server is open source, under the Apache-2 license
Actionhero runs on Linux, OS X, and Windows
You always have access to the Actionhero team via Slack and Github
We provide support for corporate & nonprofit customers starting at a flat rate of $200/hr. Our services include:
We have packages appropriate for all company sizes. Contact us to learn more.
We provide support for corporate & nonprofit customers starting at a flat rate of $200/hr. Our services include:
We have packages appropriate for all company sizes. Contact us to learn more.
For larger customers in need of a support contract, we offer an enterprise plan including everything in the Premium plan plus: