代码拉取完成,页面将自动刷新
'use strict';
/**
* This is the Form.io application server.
*/
const express = require('express');
const nunjucks = require('nunjucks');
const fs = require('fs-extra');
const path = require('path');
const util = require('./src/util/util');
require('colors');
const Q = require('q');
const test = process.env.TEST_SUITE;
const noInstall = process.env.NO_INSTALL;
module.exports = function(options) {
options = options || {};
const q = Q.defer();
util.log('');
const rl = require('readline').createInterface({
input: require('fs').createReadStream('logo.txt')
});
rl.on('line', function(line) {
util.log(
line.substring(0,4) +
line.substring(4, 30).cyan.bold +
line.substring(30, 33) +
line.substring(33, 42).green.bold +
line.substring(42)
);
});
rl.on('close', function() {
// Print the welcome screen.
util.log('');
util.log(fs.readFileSync('welcome.txt').toString().green);
});
// Use the express application.
const app = options.app || express();
// Use the given config.
const config = options.config || require('config');
// Configure nunjucks.
nunjucks.configure('client', {
autoescape: true,
express: app
});
// Mount the client application.
app.use('/', express.static(path.join(__dirname, '/client/dist')));
// Load the form.io server.
const server = options.server || require('./index')(config);
const hooks = options.hooks || {};
app.use(server.formio.middleware.restrictRequestTypes);
server.init(hooks).then(function(formio) {
// Called when we are ready to start the server.
const start = function() {
// Start the application.
if (fs.existsSync('app')) {
const application = express();
application.use('/', express.static(path.join(__dirname, '/app/dist')));
config.appPort = config.appPort || 8080;
application.listen(config.appPort);
const appHost = `http://localhost:${config.appPort}`;
util.log(` > Serving application at ${appHost.green}`);
}
// Mount the Form.io API platform.
app.use(options.mount || '/', server);
// Allow tests access server internals.
app.formio = formio;
// Listen on the configured port.
return q.resolve({
server: app,
config: config
});
};
// Which items should be installed.
const install = {
download: false,
extract: false,
import: false,
user: false
};
// Check for the client folder.
if (!fs.existsSync('client') && !test && !noInstall) {
install.download = true;
install.extract = true;
}
// See if they have any forms available.
formio.db.collection('forms').estimatedDocumentCount(function(err, numForms) {
// If there are forms, then go ahead and start the server.
if ((!err && numForms > 0) || test || noInstall) {
if (!install.download && !install.extract) {
return start();
}
}
// Import the project and create the user.
install.import = true;
install.user = true;
// Install.
require('./install')(formio, install, function(err) {
if (err) {
if (err !== 'Installation canceled.') {
return util.log(err.message);
}
}
// Start the server.
start();
});
});
});
return q.promise;
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。