Skip to content

Commit

Permalink
Testing server: Serve text files as unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
Joris-van-der-Wel committed Nov 12, 2018
1 parent 461b01b commit aa0bb67
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/server/index.js
Expand Up @@ -12,6 +12,10 @@ const morgan = require('morgan');
const staticDirectoryPath = pathResolve(__dirname, './static');
const app = express();

const isTextMime = mimeType => {
return /^text\//.test(mimeType) || mimeType === 'application/javascript';
};

app.set('x-powered-by', false);
app.use(morgan('dev'));

Expand Down Expand Up @@ -58,7 +62,8 @@ app.get('/static/*', (request, response, next) => {
return;
}

response.setHeader('Content-Type', mime.getType(path));
const mimeType = mime.getType(path);
response.setHeader('Content-Type', isTextMime(mimeType) ? `${mimeType}; charset=utf-8` : mimeType);

const readStream = createReadStream(path);

Expand Down

0 comments on commit aa0bb67

Please sign in to comment.