1.2.1 • Published 2 years ago
static-content v1.2.1
Http Server static middleware
- Binary/String files html|scripts|styles|texts|json|.etc:
- cache
- gzip
- File
read
middlewares. Refer to atma-io for documentation. - Virtual files
Binary streams images|audio|video|pdf|.etc:
- Range requests
Best works with atma-server
API
require('static-content'):StaticContentMiddleware;
StaticContentMiddleware {
create: function(settings:StaticContentSettings): function(req, res, next, AppConfig),
respond: function(req, res, next, AppConfig):null,
send: ExpressSend,
Cache: Object {
status: function(enabled:Boolean)
remove: function(path:String)
}
}
StaticContentSettings {
// Optional, static root folder
base: String
// Add or overwrite some mimeTypes
mimeTypes: { MimeTypeString: Array<Extension> }
extensions: MimeTypeString || Object {
mimeType: MimeTypeString,
// When utf8 is set, then file will be also cached and gzipped
encoding: 'UTF-8' || null,
// In seconds
maxAge: Number
},
defaultMimeType: MimeTypeString,
// Optional, set of default Headers
headers: Object
}
AppConfig {
// Static root folder resolving:
// 1) Check `static` property in config
// 2) Check `base` property in config
// 3) otherwise, take CWD
static: String
base: String
}
ExpressSend = function(req, url, ExpressSettings)
ExpressSend {
maxage: function(ms:Number): Self,
pipe: function(res),
// override handlers, support:
// - `directory`
// - `error`
on: function(event:String, function(error:Object))
}
ExpressSettings {
// base path
root: String,
// default `index.html` file
index: String
}
Examples
NodeJS HTTP
require('http')
.createServer(require('static-content').create({ base: './content' }))
.listen(5777);
Atma-Root-Application with ConnectJS
atma
.server
.Application({
configs: '/server/configs/*.yml'
})
.done(function(app){
var server = connect()
// dynamic content response
.use(app.responder({
// if dynamic endpoint is found from
// Handlers | RESTful services | Pages
// middleware pipeline will be run before calling the endpoint
middleware: [
connect.query(),
connect.cookieParser(),
connect.bodyParser(),
connect.session({
// ..
}),
passport.initialize(),
passport.session()
]
}))
// Atma-Server static content middleware
.use(require('static-content').create({
base: './public/'
}))
.listen(5777);
});
Atma-Sub-Application
module.exports = atma
.server
.Application({})
.done(function(app){
app.responders([
// dynamic content response
app.responder({
// if dynamic endpoint is found from
// Handlers | RESTful services | Pages
// middleware pipeline will be run before calling the endpoint
middleware: [
connect.bodyParser(),
// ...
]
}),
// Atma-Server static content middleware
require('static-content').respond
]);
});
The MIT License
1.2.1
2 years ago
1.1.28
4 years ago
1.1.27
6 years ago
1.1.25
8 years ago
1.1.24
8 years ago
1.1.23
9 years ago
1.0.22
9 years ago
1.0.21
10 years ago
1.0.20
10 years ago
1.0.19
10 years ago
1.0.18
10 years ago
1.0.17
10 years ago
1.0.16
10 years ago
1.0.15
10 years ago
1.0.14
10 years ago
1.0.13
10 years ago
1.0.12
10 years ago
1.0.11
10 years ago
1.0.10
10 years ago
1.0.9
10 years ago
1.0.7
10 years ago
1.0.6
10 years ago
1.0.4
10 years ago
1.0.3
10 years ago
1.0.2
10 years ago