📜  为什么 bodyparser 是下划线 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:06.853000             🧑  作者: Mango

代码示例1
var port = process.env.PORT || 8080; // set our port
var express = require('express');
var app = express();
var bodyParser = require('body-parser')
var cors = require('cors');
var indexRouter = require("./server/routes/index");
var http = require('http').Server(app);
const path = require('path')

const Licence = require('./server/CronJob/CronJob');

http.listen(port);

app.use(cors());

app.use(bodyParser.json({ limit: '50mb' }));

app.use(bodyParser.json({
    type: 'application/vnd.api+json'
}));

app.use(bodyParser.urlencoded({
    limit: '50mb',
    extended: true,
    parameterLimit: 50000
}));


// parse application/json
app.use(express.json());
app.use(express.urlencoded()); //Parse URL-encoded bodies


app.use(function (req, res, next) {
    res.header("Access-Control-Allow-Origin", '*');
    res.header("Access-Control-Allow-Credentials", true);
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    res.header("Access-Control-Allow-Headers", 'Origin,X-Requested-With,Content-Type,Accept,content-type,application/json');
    res.header("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0");
    next();
});

app.use(express.static(path.join(__dirname, "/build")));

app.use(indexRouter);

app.get('/*', function (req, res) {
    res.sendFile(path.join(__dirname, '/build/index.html'), function (err) {
        if (err) {
            res.status(500).send(err)
        }
    })
})

// Licence.licenceExpire();

console.log('Magic happens on port ' + port); // shoutout to the user

exports = module.exports = app;