node.js - Node Connect Static set Content-type text/plain not working -
i trying set content type of files served connect.static text/plain. thought work, connect seems still detecting content type fomr extension mime module.
var connect = require("connect") connect() .use(connect.static(__dirname + "/public")) .use(function(req, res, next) { res.setheader("content-type", "text/plain"); }) .listen(process.env.port); is there easy way of doing this? maybe screwing around in connects instance of mime before can it? or have rewrite connects static middleware?
if have control of filenames within public directory, easiest approach ensure end in '.txt', mime map provides send function correct content-type.
failing that, change default mime type:
var connect = require("connect") var mime = connect.static.mime; mime.default_type = mime.lookup('text'); connect() .use(connect.static(__dirname + "/public")) .listen(process.env.port); alternatively, if want every file served text/plain, set content-type header before static middleware invoked. adds header if isn't present on response:
var connect = require("connect") connect() .use(function(req, res, next) { res.setheader("content-type", "text/plain"); next(); }) .use(connect.static(__dirname + "/public")) .listen(process.env.port);
Comments
Post a Comment