2018-07-18 15:54:43 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/server/routes/get-index.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: route
|
|
|
|
|
|
|
|
GET /
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2019-08-14 22:00:01 +00:00
|
|
|
var zlib = require("zlib");
|
2019-01-27 16:23:24 +00:00
|
|
|
|
2018-07-18 15:54:43 +00:00
|
|
|
exports.method = "GET";
|
|
|
|
|
|
|
|
exports.path = /^\/$/;
|
|
|
|
|
|
|
|
exports.handler = function(request,response,state) {
|
2019-08-14 22:00:01 +00:00
|
|
|
var acceptEncoding = request.headers["accept-encoding"];
|
|
|
|
if(!acceptEncoding) {
|
|
|
|
acceptEncoding = "";
|
|
|
|
}
|
|
|
|
var text = state.wiki.renderTiddler(state.server.get("root-render-type"),state.server.get("root-tiddler")),
|
|
|
|
responseHeaders = {
|
2019-01-27 16:23:24 +00:00
|
|
|
"Content-Type": state.server.get("root-serve-type")
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
If the gzip=yes flag for `listen` is set, check if the user agent permits
|
|
|
|
compression. If so, compress our response. Note that we use the synchronous
|
|
|
|
functions from zlib to stay in the imperative style. The current `Server`
|
|
|
|
doesn't depend on this, and we may just as well use the async versions.
|
|
|
|
*/
|
|
|
|
if(state.server.enableGzip) {
|
|
|
|
if (/\bdeflate\b/.test(acceptEncoding)) {
|
2019-08-14 22:00:01 +00:00
|
|
|
responseHeaders["Content-Encoding"] = "deflate";
|
2019-01-27 16:23:24 +00:00
|
|
|
text = zlib.deflateSync(text);
|
|
|
|
} else if (/\bgzip\b/.test(acceptEncoding)) {
|
2019-08-14 22:00:01 +00:00
|
|
|
responseHeaders["Content-Encoding"] = "gzip";
|
2019-01-27 16:23:24 +00:00
|
|
|
text = zlib.gzipSync(text);
|
|
|
|
}
|
|
|
|
}
|
2019-08-14 22:00:01 +00:00
|
|
|
response.writeHead(200,responseHeaders);
|
2019-01-27 16:23:24 +00:00
|
|
|
response.end(text);
|
2018-07-18 15:54:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}());
|