目录结构
index.js引入config.json
config = JSON.parse(fs.readFileSync('./config/config.json'));
visti_port = config.visti_port; //端口
path = require('path')
const log4js = require('./logs.js')
const logger = log4js.getLogger() //根据需要获取logger
const errlogger = log4js.getLogger('err')
const othlogger = log4js.getLogger('oth')
// var NODE_ENV = process.env.NODE_ENV; //获取开发环境的状态 development 开发环境 release 正式版本环境
bodyParser = require('body-parser');
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
require("body-parser-xml")(bodyParser);
PrettyError = require('pretty-error');
pe = new PrettyError();
pe.skipNodeFiles();
pe.skipPackage('Exa');
pe.start();
app.engine('html', require('ejs').renderFile); // view engine setup
app.set('view engine', 'html');
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
return next();
});
app.use(express["static"](path.resolve(__dirname, '../../') + '/views'));
app.use('/', express["static"](path.resolve(__dirname, '../../') + '/mobile'));
app.use('/admin', express["static"](path.resolve(__dirname, '../../') + '/admin'));
app.use('/config', express["static"]('./config'));
app.use('/isLogin', express["static"](path.resolve(__dirname, '../../') + '/src/views/index.html'));
app.use(function(req, res, next) {
if (req.url == '/pay/api_notify') {
req.headers['content-type'] = 'application/x-www-form-urlencoded';
}
next();
});
fs.existsSync('./config/upload') || fs.mkdirSync('./config/upload');
fs.existsSync('./config/pdf') || fs.mkdirSync('./config/pdf');
app.use(bodyParser.xml({
limit: "1MB", // Reject payload bigger than 1 MB
xmlParseOptions: {
normalize: true, // Trim whitespace inside text nodes
normalizeTags: true, // Transform tags to lowercase
explicitArray: false // Only put nodes in array if >1
},
verify: function(req, res, buf, encoding) {
if (buf && buf.length) {
// Store the raw XML
req.rawBody = buf.toString(encoding || "utf8");
}
}
}));
app.use(bodyParser.json());
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(function(err, req, res, next) {
return next();
});
log4js.useLogger(app, logger)
log4js.useLogger(app, errlogger)
log4js.useLogger(app, othlogger)
index.js中读取JSON 用 fs.readFileSync(’’)
**代码中读取JSON用$.getJSON()获取 **