2016-02-15 23:47:53 +08:00
|
|
|
|
/*
|
|
|
|
|
globals require console
|
|
|
|
|
*/
|
2014-10-31 23:42:58 +08:00
|
|
|
|
var Express = require('express');
|
|
|
|
|
var Http = require('http');
|
2014-12-04 17:53:47 +08:00
|
|
|
|
var Fs = require('fs');
|
2017-03-02 00:23:34 +08:00
|
|
|
|
var Package = require('./package.json');
|
2017-05-19 22:56:45 +08:00
|
|
|
|
var Path = require("path");
|
2018-01-26 22:24:07 +08:00
|
|
|
|
var nThen = require("nthen");
|
2020-02-28 02:48:19 +08:00
|
|
|
|
var Util = require("./lib/common-util");
|
2020-02-29 01:01:52 +08:00
|
|
|
|
var Default = require("./lib/defaults");
|
2020-06-26 01:14:26 +08:00
|
|
|
|
var Keys = require("./lib/keys");
|
2014-10-31 23:42:58 +08:00
|
|
|
|
|
2019-04-17 19:48:39 +08:00
|
|
|
|
var config = require("./lib/load-config");
|
2020-10-12 20:09:53 +08:00
|
|
|
|
var Env = require("./lib/env").create(config);
|
2019-04-01 20:39:32 +08:00
|
|
|
|
|
2019-12-24 06:15:07 +08:00
|
|
|
|
var app = Express();
|
2016-10-07 04:44:58 +08:00
|
|
|
|
|
2021-03-22 16:42:14 +08:00
|
|
|
|
var canonicalizeOrigin = function (s) {
|
|
|
|
|
return (s || '').trim().replace(/\/+$/, '');
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-29 01:01:52 +08:00
|
|
|
|
(function () {
|
|
|
|
|
// you absolutely must provide an 'httpUnsafeOrigin'
|
|
|
|
|
if (typeof(config.httpUnsafeOrigin) !== 'string') {
|
|
|
|
|
throw new Error("No 'httpUnsafeOrigin' provided");
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 16:42:14 +08:00
|
|
|
|
config.httpUnsafeOrigin = canonicalizeOrigin(config.httpUnsafeOrigin);
|
2020-04-06 22:16:02 +08:00
|
|
|
|
if (typeof(config.httpSafeOrigin) === 'string') {
|
2021-03-22 16:42:14 +08:00
|
|
|
|
config.httpSafeOrigin = canonicalizeOrigin(config.httpSafeOrigin);
|
2020-04-06 22:16:02 +08:00
|
|
|
|
}
|
2020-02-29 01:01:52 +08:00
|
|
|
|
|
|
|
|
|
// fall back to listening on a local address
|
|
|
|
|
// if httpAddress is not a string
|
|
|
|
|
if (typeof(config.httpAddress) !== 'string') {
|
|
|
|
|
config.httpAddress = '127.0.0.1';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// listen on port 3000 if a valid port number was not provided
|
|
|
|
|
if (typeof(config.httpPort) !== 'number' || config.httpPort > 65535) {
|
|
|
|
|
config.httpPort = 3000;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 04:21:23 +08:00
|
|
|
|
if (typeof(config.httpSafeOrigin) !== 'string') {
|
2021-04-15 20:33:13 +08:00
|
|
|
|
Env.NO_SANDBOX = true;
|
2020-02-29 01:01:52 +08:00
|
|
|
|
if (typeof(config.httpSafePort) !== 'number') {
|
|
|
|
|
config.httpSafePort = config.httpPort + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 20:09:53 +08:00
|
|
|
|
if (Env.DEV_MODE) { return; }
|
2020-02-29 01:01:52 +08:00
|
|
|
|
console.log(`
|
|
|
|
|
m m mm mmmmm mm m mmmmm mm m mmm m
|
|
|
|
|
# # # ## # "# #"m # # #"m # m" " #
|
|
|
|
|
" #"# # # # #mmmm" # #m # # # #m # # mm #
|
|
|
|
|
## ##" #mm# # "m # # # # # # # # #
|
|
|
|
|
# # # # # " # ## mm#mm # ## "mmm" #
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
console.log("\nNo 'httpSafeOrigin' provided.");
|
|
|
|
|
console.log("Your configuration probably isn't taking advantage of all of CryptPad's security features!");
|
|
|
|
|
console.log("This is acceptable for development, otherwise your users may be at risk.\n");
|
|
|
|
|
|
|
|
|
|
console.log("Serving sandboxed content via port %s.\nThis is probably not what you want for a production instance!\n", config.httpSafePort);
|
|
|
|
|
}
|
|
|
|
|
}());
|
|
|
|
|
|
2020-10-27 10:42:23 +08:00
|
|
|
|
var applyHeaderMap = function (res, map) {
|
|
|
|
|
for (let header in map) { res.setHeader(header, map[header]); }
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-18 17:48:29 +08:00
|
|
|
|
var setHeaders = (function () {
|
2020-02-29 01:01:52 +08:00
|
|
|
|
// load the default http headers unless the admin has provided their own via the config file
|
|
|
|
|
var headers;
|
|
|
|
|
|
|
|
|
|
var custom = config.httpHeaders;
|
|
|
|
|
// if the admin provided valid http headers then use them
|
|
|
|
|
if (custom && typeof(custom) === 'object' && !Array.isArray(custom)) {
|
2020-10-09 15:58:13 +08:00
|
|
|
|
headers = Util.clone(custom);
|
2020-02-29 01:01:52 +08:00
|
|
|
|
} else {
|
|
|
|
|
// otherwise use the default
|
|
|
|
|
headers = Default.httpHeaders();
|
|
|
|
|
}
|
2016-10-07 04:37:25 +08:00
|
|
|
|
|
2020-02-29 01:01:52 +08:00
|
|
|
|
// next define the base Content Security Policy (CSP) headers
|
|
|
|
|
if (typeof(config.contentSecurity) === 'string') {
|
|
|
|
|
headers['Content-Security-Policy'] = config.contentSecurity;
|
2017-06-15 20:45:01 +08:00
|
|
|
|
if (!/;$/.test(headers['Content-Security-Policy'])) { headers['Content-Security-Policy'] += ';' }
|
2017-06-07 15:51:10 +08:00
|
|
|
|
if (headers['Content-Security-Policy'].indexOf('frame-ancestors') === -1) {
|
|
|
|
|
// backward compat for those who do not merge the new version of the config
|
|
|
|
|
// when updating. This prevents endless spinner if someone clicks donate.
|
2017-08-17 21:41:04 +08:00
|
|
|
|
// It also fixes the cross-domain iframe.
|
|
|
|
|
headers['Content-Security-Policy'] += "frame-ancestors *;";
|
2017-06-07 15:51:10 +08:00
|
|
|
|
}
|
2020-02-29 01:01:52 +08:00
|
|
|
|
} else {
|
|
|
|
|
// use the default CSP headers constructed with your domain
|
|
|
|
|
headers['Content-Security-Policy'] = Default.contentSecurity(config.httpUnsafeOrigin);
|
2017-03-02 00:23:34 +08:00
|
|
|
|
}
|
2020-02-29 01:01:52 +08:00
|
|
|
|
|
2020-10-09 15:58:13 +08:00
|
|
|
|
const padHeaders = Util.clone(headers);
|
2020-02-29 01:01:52 +08:00
|
|
|
|
if (typeof(config.padContentSecurity) === 'string') {
|
|
|
|
|
padHeaders['Content-Security-Policy'] = config.padContentSecurity;
|
|
|
|
|
} else {
|
|
|
|
|
padHeaders['Content-Security-Policy'] = Default.padContentSecurity(config.httpUnsafeOrigin);
|
2017-03-02 00:23:34 +08:00
|
|
|
|
}
|
2016-10-18 17:48:29 +08:00
|
|
|
|
if (Object.keys(headers).length) {
|
2017-03-02 00:23:34 +08:00
|
|
|
|
return function (req, res) {
|
2020-10-27 10:42:23 +08:00
|
|
|
|
// apply a bunch of cross-origin headers for XLSX export in FF and printing elsewhere
|
|
|
|
|
applyHeaderMap(res, {
|
|
|
|
|
"Cross-Origin-Opener-Policy": /^\/sheet\//.test(req.url)? 'same-origin': '',
|
|
|
|
|
"Cross-Origin-Embedder-Policy": 'require-corp',
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-30 13:08:03 +08:00
|
|
|
|
if (Env.NO_SANDBOX) { // handles correct configuration for local development
|
|
|
|
|
// https://stackoverflow.com/questions/11531121/add-duplicate-http-response-headers-in-nodejs
|
2021-04-15 22:13:03 +08:00
|
|
|
|
applyHeaderMap(res, {
|
|
|
|
|
"Cross-Origin-Resource-Policy": 'cross-origin',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-03 13:41:06 +08:00
|
|
|
|
// Don't set CSP headers on /api/config because they aren't necessary and they cause problems
|
|
|
|
|
// when duplicated by NGINX in production environments
|
2021-04-15 20:33:13 +08:00
|
|
|
|
if (/^\/api\/(broadcast|config)/.test(req.url)) {
|
2021-04-30 13:08:03 +08:00
|
|
|
|
/*
|
|
|
|
|
if (Env.NO_SANDBOX) {
|
2021-04-15 20:33:13 +08:00
|
|
|
|
applyHeaderMap(res, {
|
|
|
|
|
"Cross-Origin-Resource-Policy": 'cross-origin',
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-30 13:08:03 +08:00
|
|
|
|
*/
|
2021-04-15 20:33:13 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-04-15 17:47:08 +08:00
|
|
|
|
applyHeaderMap(res, {
|
|
|
|
|
"Cross-Origin-Resource-Policy": 'cross-origin',
|
|
|
|
|
});
|
|
|
|
|
|
2020-10-27 10:42:23 +08:00
|
|
|
|
// targeted CSP, generic policies, maybe custom headers
|
2019-03-01 00:08:19 +08:00
|
|
|
|
const h = [
|
2020-01-21 21:39:12 +08:00
|
|
|
|
/^\/common\/onlyoffice\/.*\/index\.html.*/,
|
2021-03-24 22:01:52 +08:00
|
|
|
|
/^\/(sheet|presentation|doc)\/inner\.html.*/,
|
2019-01-28 19:18:18 +08:00
|
|
|
|
].some((regex) => {
|
2020-04-03 22:37:23 +08:00
|
|
|
|
return regex.test(req.url);
|
|
|
|
|
}) ? padHeaders : headers;
|
2020-10-27 10:42:23 +08:00
|
|
|
|
applyHeaderMap(res, h);
|
2016-10-18 17:48:29 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return function () {};
|
|
|
|
|
}());
|
2016-10-07 05:02:30 +08:00
|
|
|
|
|
2017-04-18 21:51:42 +08:00
|
|
|
|
(function () {
|
|
|
|
|
if (!config.logFeedback) { return; }
|
|
|
|
|
|
|
|
|
|
const logFeedback = function (url) {
|
|
|
|
|
url.replace(/\?(.*?)=/, function (all, fb) {
|
2020-10-12 20:09:53 +08:00
|
|
|
|
if (!config.log) { return; }
|
2019-04-09 00:11:36 +08:00
|
|
|
|
config.log.feedback(fb, '');
|
2017-04-18 21:51:42 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
app.head(/^\/common\/feedback\.html/, function (req, res, next) {
|
|
|
|
|
logFeedback(req.url);
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
}());
|
|
|
|
|
|
2020-11-24 23:38:31 +08:00
|
|
|
|
app.use('/blob', function (req, res, next) {
|
|
|
|
|
if (req.method === 'HEAD') {
|
|
|
|
|
Express.static(Path.join(__dirname, (config.blobPath || './blob')), {
|
|
|
|
|
setHeaders: function (res, path, stat) {
|
|
|
|
|
res.set('Access-Control-Allow-Origin', '*');
|
|
|
|
|
res.set('Access-Control-Allow-Headers', 'Content-Length');
|
|
|
|
|
res.set('Access-Control-Expose-Headers', 'Content-Length');
|
|
|
|
|
}
|
|
|
|
|
})(req, res, next);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
2019-08-27 00:39:23 +08:00
|
|
|
|
app.use(function (req, res, next) {
|
|
|
|
|
if (req.method === 'OPTIONS' && /\/blob\//.test(req.url)) {
|
|
|
|
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
|
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
|
|
|
res.setHeader('Access-Control-Allow-Headers', 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range');
|
|
|
|
|
res.setHeader('Access-Control-Max-Age', 1728000);
|
|
|
|
|
res.setHeader('Content-Type', 'application/octet-stream; charset=utf-8');
|
|
|
|
|
res.setHeader('Content-Length', 0);
|
|
|
|
|
res.statusCode = 204;
|
|
|
|
|
return void res.end();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 00:23:34 +08:00
|
|
|
|
setHeaders(req, res);
|
|
|
|
|
if (/[\?\&]ver=[^\/]+$/.test(req.url)) { res.setHeader("Cache-Control", "max-age=31536000"); }
|
2020-10-27 10:42:23 +08:00
|
|
|
|
else { res.setHeader("Cache-Control", "no-cache"); }
|
2016-10-07 04:37:25 +08:00
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
2014-10-31 23:42:58 +08:00
|
|
|
|
app.use(Express.static(__dirname + '/www'));
|
|
|
|
|
|
2016-10-18 17:48:29 +08:00
|
|
|
|
// FIXME I think this is a regression caused by a recent PR
|
|
|
|
|
// correct this hack without breaking the contributor's intended behaviour.
|
2016-12-29 00:11:06 +08:00
|
|
|
|
|
2020-02-29 01:01:52 +08:00
|
|
|
|
var mainPages = config.mainPages || Default.mainPages();
|
2016-12-29 00:11:06 +08:00
|
|
|
|
var mainPagePattern = new RegExp('^\/(' + mainPages.join('|') + ').html$');
|
2018-02-09 23:17:40 +08:00
|
|
|
|
app.get(mainPagePattern, Express.static(__dirname + '/customize'));
|
2016-12-29 00:11:06 +08:00
|
|
|
|
app.get(mainPagePattern, Express.static(__dirname + '/customize.dist'));
|
2016-10-18 17:48:29 +08:00
|
|
|
|
|
2017-06-19 17:29:13 +08:00
|
|
|
|
app.use("/blob", Express.static(Path.join(__dirname, (config.blobPath || './blob')), {
|
2020-10-12 20:09:53 +08:00
|
|
|
|
maxAge: Env.DEV_MODE? "0d": "365d"
|
2017-06-19 17:29:13 +08:00
|
|
|
|
}));
|
2018-04-13 23:49:17 +08:00
|
|
|
|
app.use("/datastore", Express.static(Path.join(__dirname, (config.filePath || './datastore')), {
|
|
|
|
|
maxAge: "0d"
|
|
|
|
|
}));
|
2018-06-19 17:31:15 +08:00
|
|
|
|
app.use("/block", Express.static(Path.join(__dirname, (config.blockPath || '/block')), {
|
|
|
|
|
maxAge: "0d",
|
|
|
|
|
}));
|
2017-04-25 23:19:13 +08:00
|
|
|
|
|
2016-07-12 18:44:44 +08:00
|
|
|
|
app.use("/customize", Express.static(__dirname + '/customize'));
|
2016-07-12 18:17:03 +08:00
|
|
|
|
app.use("/customize", Express.static(__dirname + '/customize.dist'));
|
2017-12-06 00:48:30 +08:00
|
|
|
|
app.use("/customize.dist", Express.static(__dirname + '/customize.dist'));
|
2016-09-27 17:53:52 +08:00
|
|
|
|
app.use(/^\/[^\/]*$/, Express.static('customize'));
|
|
|
|
|
app.use(/^\/[^\/]*$/, Express.static('customize.dist'));
|
2015-01-31 01:12:20 +08:00
|
|
|
|
|
2021-04-12 15:49:11 +08:00
|
|
|
|
// if dev mode: never cache
|
|
|
|
|
var cacheString = function () {
|
|
|
|
|
return (Env.FRESH_KEY? '-' + Env.FRESH_KEY: '') + (Env.DEV_MODE? '-' + (+new Date()): '');
|
|
|
|
|
};
|
2020-02-28 02:48:19 +08:00
|
|
|
|
|
2021-04-12 15:49:11 +08:00
|
|
|
|
var makeRouteCache = function (template, cacheName) {
|
2020-02-28 02:48:19 +08:00
|
|
|
|
var cleanUp = {};
|
2021-04-12 15:49:11 +08:00
|
|
|
|
var cache = Env[cacheName] = Env[cacheName] || {};
|
2020-02-28 02:48:19 +08:00
|
|
|
|
|
|
|
|
|
return function (req, res) {
|
|
|
|
|
var host = req.headers.host.replace(/\:[0-9]+/, '');
|
|
|
|
|
res.setHeader('Content-Type', 'text/javascript');
|
|
|
|
|
// don't cache anything if you're in dev mode
|
2020-10-12 20:09:53 +08:00
|
|
|
|
if (Env.DEV_MODE) {
|
2020-02-28 02:48:19 +08:00
|
|
|
|
return void res.send(template(host));
|
|
|
|
|
}
|
|
|
|
|
// generate a lookup key for the cache
|
|
|
|
|
var cacheKey = host + ':' + cacheString();
|
2020-10-09 15:58:13 +08:00
|
|
|
|
|
2020-10-12 20:09:53 +08:00
|
|
|
|
// FIXME mutable
|
|
|
|
|
// we must be able to clear the cache when updating any mutable key
|
2020-02-28 02:48:19 +08:00
|
|
|
|
// if there's nothing cached for that key...
|
2021-04-12 15:49:11 +08:00
|
|
|
|
if (!cache[cacheKey]) {
|
2020-02-28 02:48:19 +08:00
|
|
|
|
// generate the response and cache it in memory
|
2021-04-12 15:49:11 +08:00
|
|
|
|
cache[cacheKey] = template(host);
|
2020-02-28 02:48:19 +08:00
|
|
|
|
// and create a function to conditionally evict cache entries
|
|
|
|
|
// which have not been accessed in the last 20 seconds
|
|
|
|
|
cleanUp[cacheKey] = Util.throttle(function () {
|
|
|
|
|
delete cleanUp[cacheKey];
|
2021-04-12 15:49:11 +08:00
|
|
|
|
delete cache[cacheKey];
|
2020-02-28 02:48:19 +08:00
|
|
|
|
}, 20000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// successive calls to this function
|
|
|
|
|
cleanUp[cacheKey]();
|
2021-04-12 15:49:11 +08:00
|
|
|
|
return void res.send(cache[cacheKey]);
|
2021-03-12 19:46:11 +08:00
|
|
|
|
};
|
2021-04-12 15:49:11 +08:00
|
|
|
|
};
|
2021-03-12 19:46:11 +08:00
|
|
|
|
|
2021-04-12 15:49:11 +08:00
|
|
|
|
var serveConfig = makeRouteCache(function (host) {
|
|
|
|
|
return [
|
|
|
|
|
'define(function(){',
|
|
|
|
|
'var obj = ' + JSON.stringify({
|
|
|
|
|
requireConf: {
|
|
|
|
|
waitSeconds: 600,
|
|
|
|
|
urlArgs: 'ver=' + Package.version + cacheString(),
|
|
|
|
|
},
|
|
|
|
|
removeDonateButton: (config.removeDonateButton === true),
|
|
|
|
|
allowSubscriptions: (config.allowSubscriptions === true),
|
|
|
|
|
websocketPath: config.externalWebsocketURL,
|
|
|
|
|
httpUnsafeOrigin: config.httpUnsafeOrigin,
|
|
|
|
|
adminEmail: Env.adminEmail,
|
|
|
|
|
adminKeys: Env.admins,
|
|
|
|
|
inactiveTime: Env.inactiveTime,
|
|
|
|
|
supportMailbox: Env.supportMailbox,
|
|
|
|
|
defaultStorageLimit: Env.defaultStorageLimit,
|
|
|
|
|
maxUploadSize: Env.maxUploadSize,
|
|
|
|
|
premiumUploadSize: Env.premiumUploadSize,
|
2021-05-05 14:37:45 +08:00
|
|
|
|
restrictRegistration: Env.restrictRegistration, // FIXME see the race condition in env.js
|
2021-04-12 15:49:11 +08:00
|
|
|
|
}, null, '\t'),
|
|
|
|
|
'obj.httpSafeOrigin = ' + (function () {
|
|
|
|
|
if (config.httpSafeOrigin) { return '"' + config.httpSafeOrigin + '"'; }
|
|
|
|
|
if (config.httpSafePort) {
|
|
|
|
|
return "(function () { return window.location.origin.replace(/\:[0-9]+$/, ':" +
|
|
|
|
|
config.httpSafePort + "'); }())";
|
|
|
|
|
}
|
|
|
|
|
return 'window.location.origin';
|
|
|
|
|
}()),
|
|
|
|
|
'return obj',
|
|
|
|
|
'});'
|
|
|
|
|
].join(';\n')
|
|
|
|
|
}, 'configCache');
|
|
|
|
|
|
|
|
|
|
var serveBroadcast = makeRouteCache(function (host) {
|
|
|
|
|
var maintenance = Env.maintenance;
|
|
|
|
|
if (maintenance && maintenance.end && maintenance.end < (+new Date())) {
|
|
|
|
|
maintenance = undefined;
|
|
|
|
|
}
|
|
|
|
|
return [
|
|
|
|
|
'define(function(){',
|
|
|
|
|
'return ' + JSON.stringify({
|
|
|
|
|
lastBroadcastHash: Env.lastBroadcastHash,
|
|
|
|
|
surveyURL: Env.surveyURL,
|
|
|
|
|
maintenance: maintenance
|
|
|
|
|
}, null, '\t'),
|
|
|
|
|
'});'
|
|
|
|
|
].join(';\n')
|
|
|
|
|
}, 'broadcastCache');
|
2021-03-12 19:46:11 +08:00
|
|
|
|
|
2020-02-28 02:48:19 +08:00
|
|
|
|
app.get('/api/config', serveConfig);
|
2021-03-12 19:46:11 +08:00
|
|
|
|
app.get('/api/broadcast', serveBroadcast);
|
2014-11-03 18:13:41 +08:00
|
|
|
|
|
2017-12-01 02:19:21 +08:00
|
|
|
|
var four04_path = Path.resolve(__dirname + '/customize.dist/404.html');
|
|
|
|
|
var custom_four04_path = Path.resolve(__dirname + '/customize/404.html');
|
|
|
|
|
|
|
|
|
|
var send404 = function (res, path) {
|
|
|
|
|
if (!path && path !== four04_path) { path = four04_path; }
|
|
|
|
|
Fs.exists(path, function (exists) {
|
2018-04-12 23:24:51 +08:00
|
|
|
|
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
2017-12-01 02:19:21 +08:00
|
|
|
|
if (exists) { return Fs.createReadStream(path).pipe(res); }
|
|
|
|
|
send404(res);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
app.use(function (req, res, next) {
|
|
|
|
|
res.status(404);
|
|
|
|
|
send404(res, custom_four04_path);
|
|
|
|
|
});
|
|
|
|
|
|
2020-10-12 20:09:53 +08:00
|
|
|
|
var httpServer = Env.httpServer = Http.createServer(app);
|
2014-12-04 17:53:47 +08:00
|
|
|
|
|
2020-01-28 06:57:39 +08:00
|
|
|
|
nThen(function (w) {
|
|
|
|
|
Fs.exists(__dirname + "/customize", w(function (e) {
|
|
|
|
|
if (e) { return; }
|
|
|
|
|
console.log("Cryptpad is customizable, see customize.dist/readme.md for details");
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (w) {
|
|
|
|
|
httpServer.listen(config.httpPort,config.httpAddress,function(){
|
|
|
|
|
var host = config.httpAddress;
|
|
|
|
|
var hostName = !host.indexOf(':') ? '[' + host + ']' : host;
|
2017-01-27 23:45:41 +08:00
|
|
|
|
|
2020-01-28 06:57:39 +08:00
|
|
|
|
var port = config.httpPort;
|
|
|
|
|
var ps = port === 80? '': ':' + port;
|
2017-03-11 01:03:15 +08:00
|
|
|
|
|
2020-01-28 06:57:39 +08:00
|
|
|
|
console.log('[%s] server available http://%s%s', new Date().toISOString(), hostName, ps);
|
|
|
|
|
});
|
2019-04-09 17:40:51 +08:00
|
|
|
|
|
2020-01-28 06:57:39 +08:00
|
|
|
|
if (config.httpSafePort) {
|
|
|
|
|
Http.createServer(app).listen(config.httpSafePort, config.httpAddress, w());
|
2019-12-24 06:39:13 +08:00
|
|
|
|
}
|
2018-01-26 22:24:07 +08:00
|
|
|
|
}).nThen(function () {
|
2020-01-28 06:57:39 +08:00
|
|
|
|
var wsConfig = { server: httpServer };
|
|
|
|
|
|
|
|
|
|
// Initialize logging then start the API server
|
|
|
|
|
require("./lib/log").create(config, function (_log) {
|
2020-10-12 20:09:53 +08:00
|
|
|
|
Env.Log = _log;
|
2020-01-28 06:57:39 +08:00
|
|
|
|
config.log = _log;
|
|
|
|
|
|
2021-01-08 17:19:04 +08:00
|
|
|
|
if (Env.OFFLINE_MODE) { return; }
|
2020-01-28 06:57:39 +08:00
|
|
|
|
if (config.externalWebsocketURL) { return; }
|
2020-10-12 20:09:53 +08:00
|
|
|
|
|
|
|
|
|
require("./lib/api").create(Env);
|
2020-01-28 06:57:39 +08:00
|
|
|
|
});
|
2018-01-26 22:24:07 +08:00
|
|
|
|
});
|
2020-01-28 06:57:39 +08:00
|
|
|
|
|
|
|
|
|
|