本文整理汇总了TypeScript中body-parser.json函数的典型用法代码示例。如果您正苦于以下问题:TypeScript json函数的具体用法?TypeScript json怎么用?TypeScript json使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: return
return (app) => {
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
};
示例2: require
import express = require('express');
import {Request, Response} from 'express';
import {raw, json, text, urlencoded, ParsedAsJson, ParsedAsText, ParsedRaw, ParsedAsUrlencoded} from 'body-parser';
const app = express();
app.post('/rawdemo', raw(), (req: Request & ParsedRaw, res: Response) => {
console.log(req.body.readUInt8(0));
});
app.post('/jsondemo', json(), (req: Request & ParsedAsJson, res: Response) => {
console.log(req.body.whatever);
});
app.post('/textdemo', text(), (req: Request & ParsedAsText, res: Response) => {
console.log(req.body.substr(3));
});
app.post('/urlencodeddemo', urlencoded(), (req: Request & ParsedAsUrlencoded, res: Response) => {
console.log(req.body.whatever);
});
示例3: Router
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* tslint:disable:max-line-length */
import {Router} from 'express';
// Einlesen von application/json im Request-Rumpf
// Fuer multimediale Daten (Videos, Bilder, Audios): raw-body
import {json} from 'body-parser';
import {getById, getByQuery, post, put, deleteFn} from './videos_request_handler';
import {validateJwt, isAdmin, isAdminMitarbeiter} from '../../iam/router/iam_request_handler';
import {validateMongoId} from '../../shared/shared';
/* tslint:enable:max-line-length */
// http://expressjs.com/en/api.html
// Ein Router ist eine "Mini-Anwendung" mit Express
const buecherRouter: Router = Router();
buecherRouter.route('/')
.get(getByQuery)
.post(validateJwt, isAdminMitarbeiter, json(), post)
.put(validateJwt, isAdminMitarbeiter, json(), put);
const idParam: string = 'id';
buecherRouter.param(idParam, validateMongoId)
.get(`/:${idParam}`, getById)
.delete(`/:${idParam}`, validateJwt, isAdmin, deleteFn);
export default buecherRouter;
示例4:
import * as controller from '../api/carController';
import * as express from 'express';
import * as bodyParser from 'body-parser';
const router = express.Router();
// Base route --- /api/v1/cars
// GET: /api/v1/cars/
router.get('/', controller.getAll);
// GET: /api/v1/cars/:id
router.get('/:id', controller.getOne);
// DELETE: /api/v1/cars/:id
router.delete('/:id', controller.remove)
router.use(bodyParser.json());
// POST: /api/v1/cars/
router.post('/', controller.create);
// PUT: /api/v1/cars/:id
router.put('/:id', controller.update);
export = router;
示例5: express
import * as express from 'express';
import * as path from 'path';
import * as logger from 'morgan';
import * as bodyParser from 'body-parser';
import * as jwter from 'jsonwebtoken';
import * as configs from './config/config';
import auth from './auth/auth';
import { UserData as users } from './models/users';
const app = express();
const auther = auth();
app.use(logger('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(auther.initialize());
app.use(express.static(path.join(__dirname, '../public')));
app.get('/', (req, res, next) => {
res.end('ok');
});
app.post('/user', auther.authenticate(), (req, res) => {
if (req.user) {
res.json({
id: req.user.id,
email: req.user.email,
});
} else {
res.json({
示例6: constructor
constructor() {
this.app = express();
this.app.use(bodyParser.json());
this.initMongoDB();
this.routes();
}
示例7: constructor
constructor() {
var fs = require('fs');
var path = require('path');
var express = require('express');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var url = require('url');
var querystring = require('querystring');
global.config = new configuration.config();
//var dal = new nodulus.data.dal();// require('./dal.js');
//var config = require('./config.js');
var webServer = new web.webServer();
//var api = require('./api.js');
var EventEmitter = require('events').EventEmitter;
global.eventServer = new EventEmitter();
var app = express();
var http = require("http").createServer(app);
var server = require('http').Server(app);
if (global.config.enableSockets) {
var socket = require('socket.io');
var io = socket.listen(server);
global.socket = io;
console.log("*** websocket is active");
var SocketUse = new network.socket(io);
}
webServer.start(server, app, function (app: any) {
});
var regexIso8601 = /^(\d{4}|\+\d{6})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})\.(\d{1,})(Z|([\-+])(\d{2}):(\d{2}))?)?)?)?$/;
app.use(bodyParser.json({
reviver: function (key: string, value: any) {
var match: any;
if (typeof value === "string" && (match = value.match(regexIso8601))) {
var milliseconds = Date.parse(match[0]);
if (!isNaN(milliseconds)) {
return new Date(milliseconds);
}
}
return value;
},
limit: '50mb',
}));
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.use('/', express.static(path.resolve('./client/')));
global.clientAppRoot = path.resolve('./client/');
//load modules
var nodulus_modules = global.config.modulesSettings;
console.log("");
console.log("***************************************************************************");
console.log("***__active nodules_____________________________________________________***");
console.log("***_____________________________________________________________________***");
for (var name of Object.keys(nodulus_modules)) {
var nodulus_module = nodulus_modules[name];
console.log("***__ " + name + " " + this.print("_", 65 - name.length) + "***");
if (nodulus_module.routes !== undefined) {
for (var x = 0; x < nodulus_module.routes.length; x++) {
app.use(nodulus_module.routes[x].route, require('../routes/' + nodulus_module.routes[x].path));
}
}
}
console.log("***_____________________________________________________________________***");
app.use("/nodulus", require('../routes/nodulus.js'));
var a = new rest.api();
a.start(app);
console.log("***_____________________________________________________________________***");
// app.use(require("nodulus-run"));
}
示例8: express
import * as React from 'react';
import * as favicon from 'serve-favicon';
import * as ReactEngine from 'react-engine';
import * as bodyParser from 'body-parser';
import * as cookieParser from 'cookie-parser';
import routes from './initiators/server-routes';
let app = express();
const PORT = 3000;
// create the view engine with `react-engine`
let engine = ReactEngine.server.create({
performanceCollector: function(stats) {}
});
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(cookieParser()); // for parsing cookies
app.engine('.js', engine);// set the engine
app.set('views', join(__dirname, '/components'));// set the view directory
app.set('view engine', 'js');// set js as the view engine
app.set('view', ReactEngine.expressView);// finally, set the custom view
app.use(express.static(join(__dirname, '/')));// expose public folder as static assets
app.use(favicon(join(__dirname, '/favicon.ico')));// Use the favicon
routes(app);// Initialize the server routes
const server = app.listen(PORT, function() {
console.log('Example app listening at http://localhost:%s', PORT);
});
示例9: next
var clientDir = __dirname + '/../static';
var buildDir = __dirname + '/../../build';
var bootstrapCssDir = __dirname + '/../../node_modules/bootstrap/dist/css';
/* MiddleWare */
var logger = ( req:express.Request, res, next) =>{
console.log("---------------------------------------------");
console.log("REQ:" + req.url);
next();
};
app.use(express.static(clientDir))
.use('/build',express.static(buildDir))
.use('/bs-css',express.static(bootstrapCssDir))
.listen(process.env.port || 7777);
app.use(logger);
app.use(parser.json());
app.use(parser.urlencoded({extended:false}));
//Error Handler
var errorHandler = (err,req,res,next) => {
console.log("ERROR!!!!");
res.status(500);
res.send(err);
}
app.use(errorHandler);
console.log (`${pjson.name} v${pjson.version} server started! - proxy:${process.env.HTTP_PROXY}`);
示例10: require
import * as express from "express";
import * as bodyParser from "body-parser";
import {registerActionsInExpressApp} from "../../src/routing-controllers";
import "./BlogController"; // this can be require("./BlogController") actually
let app = express(); // create express server
app.use(bodyParser.json()); // setup body parser
let controllerRunner = registerActionsInExpressApp(app); // register controllers routes in our express application
controllerRunner.isLogErrorsEnabled = true; // enable error logging of exception error into console
controllerRunner.isStackTraceEnabled = true; // enable adding of stack trace to response message
app.listen(3003); // run express app
console.log("Express server is running on port 3003. Open http://localhost:3003/blogs/");