本文整理汇总了TypeScript中body-parser.urlencoded函数的典型用法代码示例。如果您正苦于以下问题:TypeScript urlencoded函数的具体用法?TypeScript urlencoded怎么用?TypeScript urlencoded使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了urlencoded函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: initBodyParser
function initBodyParser (app : express.Application) : void {
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
}
示例2: require
require('source-map-support').install();
import express = require('express');
import path = require('path');
import {newsAPI} from './api/news';
var port: number = process.env.PORT || 8080;
var app = express();
var compression = require('compression');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
mongoose.connect('mongodb://localhost/coherent-info-portal');
app.use(compression());
app.use(bodyParser.urlencoded({'extended': 'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json());
app.use(express.static(path.resolve(process.cwd(), 'client/')));
var renderIndex = (req: express.Request, res: express.Response) => {
res.sendFile(path.resolve(process.cwd(), 'client/index.html'));
};
newsAPI(app);
app.get('/*', renderIndex);
var server = app.listen(port, function() {
var host = server.address().address;
var port = server.address().port;
console.log('This express app is listening on port:' + port);
});
示例3: 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);
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"));
}
示例4: startApp
startApp() {
var http = require('http');
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var multer = require('multer');
//Retrive
var mongo = require('mongodb');
var monk = require('monk');
//var db = monk('127.0.0.1:27017/MATA');
var db = monk('mongodb://heroku_21q1wxnl:otpu73q7n7h9o1ff9lvmbifs8q@ds047315.mongolab.com:47315/heroku_21q1wxnl');
var mongoose = require('mongoose'); // #al# : mongoose connection
//mongoose.connect('mongodb://localhost/MATA'); // #al# : mongoose connection
mongoose.connect('mongodb://heroku_21q1wxnl:otpu73q7n7h9o1ff9lvmbifs8q@ds047315.mongolab.com:47315/heroku_21q1wxnl'); // #al# : mongoose connection
var easyimg = require('easyimage');
var imagemagick = require('imagemagick');
var routes = require('./routes');
var app = express();
app.locals.moment = require('moment');
// view engine setup
//app.set('views', path.join(__dirname, 'views'));
app.set('views', path.join(__dirname, 'ViewsStyled'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(multer({dest:'./uploads/fullsize/'}).single('image'));
//app.use(multer({dest:'./uploads/profilepictures/'}).single('image'));
// Make our db accessible to our router
app.use(function(req, res, next) {
req.db = db;
req.mongoose = mongoose;
next();
});
app.use('/', routes);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
}
示例5: function
export let initAppAndDatabase = async function (): Promise<AppPlusDatabase> {
try {
/* config and logger init */
let mode: string
let logmode: string
mode = process.env.NODE_ENV || 'development'
mode === 'production' ? logmode = 'combined' : logmode = 'short'
let config = await getServerConfig(mode)
let logger = getLogger(config.logfile)
try {
// database and app init
let app = express()
let database = await initDatabase()
/* express middlewares */
// security
app.use(helmet())
// authentication
app.use(passport.initialize())
configurePassport(database, passport)
// logs
if (mode === 'development') { app.use(morgan('dev')) }
app.use(morgan(logmode, { 'stream': logger['morganStream'] }))
// requests
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
/* routes */
app.use(generateRoutes(database, logger))
/* handlers */
// database disconnection and SIGINT handlers
database.connection.once('disconnected', () => {
logger.info('server is down')
process.exit(0)
})
process.once('SIGINT', () => {
logger.info('Server is down')
database.connection.close(() => {
process.exit(0)
})
})
// request error handler
app.use((err, req, res, next) => {
let stack: string
mode === 'development' ? stack = err.stack : stack = ''
return res.status(err['status'] || 500).json({
message: err.message,
stack: stack,
success: false
})
})
return {
app: app,
database: database,
logger: logger
}
} catch (err) {
logger.error(err)
throw err
}
} catch (err) {
console.log(err)
throw err
}
}
示例6: function
//next();
//});
//===============================================
// express config start
//===============================================
router.use(express.static(path.resolve(__dirname, 'public')));
router.set('view engine', 'ejs'); // set up ejs for templating
router.set('views',path.join(__dirname,'/app/views'));
router.use(compression());
//router.use(multer({ dest: './uploads/'}));
//router.use(busboy());
// parse application/json
router.use(bodyParser.json());
// parse application/x-www-form-urlencoded
router.use(bodyParser.urlencoded({extended:true})); // get information from html forms
// parse application/vnd.api+json as json
router.use(bodyParser.json({ type: 'application/vnd.api+json' }));
router.use(cookieParser()); // required before session
router.use(methodOverride());
//===============================================
// express config start
//===============================================
//load file to write url file js
var eio_contents = fs.readFileSync(__dirname + '/node_modules/engine.io-client/engine.io.js').toString();
router.get('/engine.io.js', function(req, res) {
//res.setHeader("Access-Control-Allow-Origin", "*");
res.send(eio_contents);
});
示例7: require
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const server = require('http').createServer(app);
const port = 8000;
app.set('jsonp callback name', 'callback');
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({extended: true, limit: '50mb'}));
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTION');
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
// Start server
server.listen(port, () => console.log('Express server listening on %d, in %s mode', port, app.get('env')));
// API definition
require('./api/sed/sed')(app);
exports = module.exports = app;
示例8: require
/// <reference path="../typings/references.ts" />
/// <reference path="./file-fetcher.ts" />
// to set up node and apache to run on the same server: http://stackoverflow.com/a/18604082/1063392
var express = require('express');
var bodyParser = require('body-parser');
var fileFetcher = require('./file-fetcher');
var domain = require('domain');
var app = express();
app.use(bodyParser.urlencoded({ extended: false, limit: 1048576 }));
app.post('/', (req, res) => {
var d = domain.create();
var responseHasBeenSent = false;
d.on('error', function(er) {
if (!responseHasBeenSent) {
responseHasBeenSent = true;
console.log(er);
res.status(500).send(er);
}
});
d.run(function() {
var start = Date.now();
fileFetcher.fetchFiles(req.body.file, (allFiles: string[]) => {
console.log('request took ' + (Date.now() - start) + ' ms to complete');
res.status(200).send(allFiles);
});
});
});
示例9: require
morgan = require('morgan'),
bodyParser = require('body-parser'),
mongoose = require('mongoose');
/* Mongo start */
mongoose.connect('mongodb://localhost/timeline');
require('./utilities/mongoScheme');
/* App */
var app = express();
app.set('port', process.env.PORT || 3000);
app.use(express.static(__dirname + '/public'));
app.use(morgan('combined'));
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.urlencoded({ extended: false })); // parse application/x-www-form-urlencoded
/* Routing */
var auth = require('./routes/auth');
app.post('/api/v1/login', auth.login);
app.post('/api/v1/registration', auth.registration);
app.get('/api/v1/profile', auth.check, auth.profile);
var tasks = require('./routes/tasks');
app.get('/api/v1/tasks', auth.check, tasks.list);
app.get('/api/v1/tasks/:id', auth.check, tasks.get);
app.post('/api/v1/tasks', auth.check, tasks.create);
app.put('/api/v1/tasks/:id', auth.check, tasks.update);
app.delete('/api/v1/tasks/:id', auth.check, tasks.delete);
示例10: middleware
private middleware(): void {
this.express.use(logger('dev'));
this.express.use(bodyParser.json());
this.express.use(bodyParser.urlencoded({ extended: false}));
this.express.use(cors());
}