本文整理匯總了TypeScript中morgan.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: initialize
function initialize() {
var config = configuration;
// Configure application settings. Consult the Express API Reference for a
// list of the available [settings](http://expressjs.com/api.html#app-settings).
var viewsDir = path.resolve(config.startupDirectory, "./views");
var stylesDir = path.resolve(config.startupDirectory, "./styles");
var publicDir = path.resolve(config.startupDirectory, "./dist/public");
config.logger.info("Views directory: %s", viewsDir);
config.logger.info("Styles directory: %s", stylesDir);
config.logger.info("Public directory: %s", publicDir);
this.set('views', viewsDir);
this.set('view engine', 'jade');
// Register Jade as a template engine.
this.engine('jade', require('jade').__express);
// Override default template extension. By default, Locomotive finds
// templates using the `name.format.engine` convention, for example
// `index.html.ejs` For some template engines, such as Jade, that find
// layouts using a `layout.engine` notation, this results in mixed conventions
// that can cuase confusion. If this occurs, you can map an explicit
// extension to a format.
this.format('html', { extension: '.jade' })
// Register formats for content negotiation. Using content negotiation,
// different formats can be served as needed by different clients. For
// example, a browser is sent an HTML response, while an API client is sent a
// JSON or XML response.
/* this.format('xml', { engine: 'xmlb' }); */
// Use middleware. Standard [Connect](http://www.senchalabs.org/connect/)
// middleware is built-in, with additional [third-party](https://github.com/senchalabs/connect/wiki)
// middleware available as separate modules.
this.use(poweredBy('Locomotive'));
this.use(morgan());
//this.use(favicon(path.resolve(publicDir, 'favicon.ico')));
this.use(cookieParser());
this.use("/src", express.static(path.resolve(config.startupDirectory, "./src")));
this.use(express.static(publicDir));
this.use(bodyParser.json());
this.use(bodyParser.urlencoded({ extended: true }));
this.use(methodOverride());
/* istanbul ignore next */
config.dataFactory = (): any => {
return new GitHubApi ({
// required
version: "3.0.0",
// optional
debug: false,
protocol: "https",
host: "api.github.com",
timeout: 5000
});
};
config.logger.debug("Common environment init completed");
}
示例2: winstonMongo
var expressWinston = require('express-winston');
var winstonMongo = require('winston-mongodb').MongoDB;
// my modules
import config = require('./config');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.enable('trust proxy'); // To get real ip
// Setup loggers
// For console, use morgan logger
app.use(logger('combined'));
// express-winston logger makes sense BEFORE the router.
// Send log to mongodb
expressWinston.requestWhitelist.push('ip');
expressWinston.requestWhitelist.push('ips');
app.use(expressWinston.logger({
transports: [
new winstonMongo({
db: config.winston.mongo.dbName,
collection: config.winston.mongo.accessLogCollName
})
]
}));
// Setup router
app.use('/', require('./route/index'));
示例3: require
var http = require('http'),
express = require('express'),
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);
示例4: require
var methodOverride = require('method-override');
var http = require('http');
var util = require('util');
var app = express();
var port = 5000;
var authRouter = require('./app/authentication/linkedin.routes')();
// set third party libraries
app.use(express.static('public'));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(methodOverride());
app.use(morgan());
app.use(session({secret: 'library'}));
app.use(passport.initialize());
app.use(passport.session());
// set routes
app.get('/', function(req, res){
res.send('Hello World');
});
app.use('/auth', authRouter);
// start server
app.listen(port, function(err){
console.log('running server on port ' + port);
示例5: require
let mockservice = require("./routes/mock");
let app = express();
app.use("/client", express.static(path.resolve("./built/client")));
app.use("/node_modules", express.static(path.resolve("./node_modules")));
app.use("/lib", express.static(path.resolve("./public/lib")));
app.use("/images", express.static(path.resolve("./public/images")));
app.engine("ejs", engine);
app.set("views", "./built/client");
app.set("view engine", "ejs");
// uncomment after placing your favicon in /public
// app.use(favicon(__dirname + "/public/favicon.ico"));
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use("/mock/*", mockservice);
app.use("/*", routes);
app.listen(9090, function() {
console.log("server started 9090 ");
});
module.exports = app;
示例6: constructor
constructor() {
var express = require("express");
var Panel = require('./panel');
var ComicWebService = require('./ComicWebService');
var Comic = require('./comic');
var TranslateWebService = require('./TranslateWebService')
let path = require('path');
let favicon = require('serve-favicon');
let stormpath = require('express-stormpath');
let logger = require('morgan');
let cookieParser = require('cookie-parser');
let bodyParser = require('body-parser');
var profile = require('./routes/profile');
var routes = require('./routes/index');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
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(stormpath.init(app, {
postRegistrationHandler: function (account, req, res, next) {
var api = new UserWebService();
api.newUser(new User("", [], [], account.customData.userType, account.email), function (error, response, body) {
var temp = JSON.parse(body);
console.log(temp['_id']);
account.customData.mongoUserID = temp["_id"];
account.save();
});
next();
},
// Function is run after someone logs in
// Checks to see if the user exists in the MongoDB
postLoginHandler: function (account, req, res, next){
if(req.user.customData.mongoUserID == undefined){
var api = new UserWebService();
api.getAUserByEmail(req.user.email, function(error:string, response:string, body:string){
if (body.toString() == "null"){
api.newUser(new User("", [], [], req.user.customData.userType.toString(), req.user.email.toString()), function(error:string, response:string, body:string){
var temp = JSON.parse(body);
req.user.customData.mongoUserID = temp["_id"];
req.user.save();
});
}else{
var temp = JSON.parse(body);
req.user.customData.mongoUserID = temp["_id"];
req.user.save();
}
});
}
next();
},
client: {
apiKey: {
id: '4F42CDDRB565RJ2LFG9O8IR3F',
secret: '3V84FQEqVIQC09AupKMmjNLxSzmXPq0vAlyDA/qgODs',
},
},
application: {
href: 'https://api.stormpath.com/v1/applications/MCCvNPvyq2KR5cl0x2POL'
},
website: true,
web: {
login: {
enabled: true,
nextUri: "/account"
},
register: {
enabled: true,
fields: {
givenName: {
enabled: true,
required: true
},
surname: {
enabled: true,
required: true
},
userType: {
enabled: false,
//.........這裏部分代碼省略.........
示例7: function
export var init = function() {
var app = express();
// Compress content
app.use(compression({
threshold: 512
}));
// view engine setup
app.set('views', path.join(__dirname, '../../views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(morgan('dev', {
stream:BunyanStream
}));
app.use(bodyParser.json({limit: '128mb'}));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, '../../public'), {maxAge: 0}));
var mongoStore = new MongoStore({
mongooseConnection: mongoose.connection,
clear_interval: 3600
});
app.use(session({
secret: options.sessionSecret,
saveUninitialized:true,
resave:true,
store: mongoStore
}));
// Remember Me middleware
app.use( function (req, res, next) {
if ( req.method == 'POST' && req.url == '/login' ) {
if ( req.body.rememberme ) {
req.session.cookie.maxAge = 90*24*60*60*1000; // Rememeber 'me' for 90 days
} else {
req.session.cookie.expires = false;
}
}
next();
});
PassportHandler.init(app);
app.get('/', function(req,res) {
if (req.isAuthenticated()) {
res.redirect(options.baseUrl + '/view');
} else {
res.redirect(options.baseUrl + '/login');
}
});
app.use('/view', ViewRoute);
app.use('/service',ServiceRoute);
ShareJSHandler.init(app, mongoStore);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
res.status(404);
res.send("404 - "+req.path+" Not Found");
});
// 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: {}
});
});
return app;
};
示例8: require
import { HgtEndpoint } from "./hgt/HgtEndpoint";
import { LinkEndpoint } from "./link/LinkEndpoint";
import { MessageEndpoint } from "./message/MessageEndpoint";
import { GommetteEndpoint } from "./gommette/GommetteEndpoint";
var express = require('express');
var logger = require('morgan');
var bodyParser = require('body-parser');
var expressResource = require('express-resource');
var compression = require('compression');
console.log("Server is starting ...");
var app = express();
app.use(logger('tiny'));
app.use(bodyParser.json());
app.use(compression());
console.log("Creating routes ...");
app.use(Authentication.authenticateUser);
app.resource('messages', MessageEndpoint);
app.resource('links', LinkEndpoint);
app.resource('scores/hgt/:channel', HgtEndpoint);
app.resource('scores/gommettes', GommetteEndpoint);
app.get('/scores/hgt/:channel/:year', HgtEndpoint.byYear);
app.get('/scores/hgt/:channel/:year/:week', HgtEndpoint.byWeek);
app.get('/scores/gommettes/:year', GommetteEndpoint.byYear);
app.get('/scores/gommettes/:year/:userId', GommetteEndpoint.byYearAndUser);
示例9: knex
import morgan from "morgan";
import { Model } from "objection";
import schema from "./schema";
dotenv.config();
const PORT = process.env.PORT || 3000;
const knx = knex({
client: "pg",
connection: process.env.DATABASE_URL,
});
Model.knex(knx);
const graphqlOptions: ExpressGraphQLOptionsFunction = (request) => ({
context: { request, knex },
schema,
});
const app = express();
app.use(morgan("dev"));
app.use("/graphql", bodyParser.json(), graphqlExpress(graphqlOptions));
app.use(express.static("public"));
// tslint:disable-next-line:no-console
app.listen(PORT, () => console.log(`Listening on :${PORT}`));
示例10: express
import logger from 'morgan'
import session from 'express-session'
import passport from 'passport'
import router from './router'
import infra from './infra'
const app = express();
// view engine setup
app.set('views', path.join(__dirname, '..', 'views'));
app.set('view engine', 'pug');
var fs = require('fs');
var stream = fs.createWriteStream('/var/log/express/app.log', { flags: 'a' });
app.use(logger('dev', { stream }));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, '..', 'public')));
var sess = {
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}
if (app.get('env') === 'production') {
app.set('trust proxy', 1) // trust first proxy