代码拉取完成,页面将自动刷新
"use strict";
var mime = require('mime');
var restify = require('restify');
var yargs = require('yargs');
yargs.options({
'port': {
'default': 8080,
'description': 'Port to listen on.'
},
'public': {
'type': 'boolean',
'default': false,
'description': 'Run a public server that listens on all interfaces.'
},
'production': {
'type': 'boolean',
'default': false,
'description': 'Run the built version of the code.'
}
});
var argv = yargs.argv;
var server = restify.createServer();
//The built in gzipResponse gzips everything, including compressed files.
//This disables gzipping for specific routes and files.
var gzipResponse = restify.gzipResponse();
server.use(function (req, res, next) {
var url = req.url;
//Tiles are pre-gzipped.
if (/\/3DTiles\/(.*)/.test(url)) {
res.header('Content-Encoding', 'gzip');
next();
return;
}
//Don't gzip things that are likely gzipped already.
var contentType = mime.lookup(url);
if (/^(image|audio|video)\//.test(contentType)) {
next();
return;
}
gzipResponse(req, res, next);
});
server.get(/.*/, restify.serveStatic({
directory: argv.production ? 'build' : 'public',
default: 'index.html',
maxAge: 0
}));
server.listen(argv.port, argv.public ? undefined : 'localhost', function () {
console.log('%s listening at %s', server.name, server.url);
});
var shuttingDown = false;
function shutdown() {
if (shuttingDown) {
return;
}
shuttingDown = true;
console.log("Closing server connections...");
server.close(function () {
console.log("Shutdown successfull.");
process.exit(0);
});
}
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。