pkg 项目打包成可执行文件

目录结构
这里写图片描述
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()获取 **

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值