本文整理汇总了TypeScript中morgan类的典型用法代码示例。如果您正苦于以下问题:TypeScript morgan类的具体用法?TypeScript morgan怎么用?TypeScript morgan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了morgan类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: function
export default function(app) {
let env = app.get('env');
app.set('views', config.root + '/server/views');
app.set('view engine', 'jade');
app.use(compression());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(cookieParser());
app.use(passport.initialize());
app.set('appPath', path.join(config.root, 'client'));
if ('production' === env) {
app.use(favicon(path.join(config.root, 'client', 'favicon.ico')));
app.use(express.static(app.get('appPath')));
app.use(morgan('dev'));
}
if ('development' === env) {
app.use(require('connect-livereload')());
}
if ('development' === env || 'test' === env) {
app.use(express.static(path.join(config.root, '.tmp')));
app.use(express.static(app.get('appPath')));
app.use(morgan('dev'));
app.use(errorHandler()); // Error handler - has to be last
}
}
开发者ID:Jeremy-Doucet,项目名称:Blog-Example-Typescript,代码行数:31,代码来源:express.ts
示例2: config
private config(): void {
this.app = express();
this.app.use(bodyParser.urlencoded({
extended: true
}));
this.app.use(bodyParser.json());
this.app.use(morgan("dev"));
this.app.set("env", DEV);
this.app.set("port", 3000);
this.app.set("views", path.resolve(__dirname, "views"));
this.app.set("view engine", "pug");
//switch(process.env.npm_package_config_target){
//case DEV:
//this.app.use(errorHandler);
this.app.locals.pretty = true;
this.app.set("env", DEV);
//break;
//case PROD:
//break;
//}
this.app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction): void => {
console.log(err.stack);
next(err);
});
//this.app.use(errorHandler);
}
开发者ID:cdhgee,项目名称:investments,代码行数:29,代码来源:AppServer.ts
示例3: register
static register(config): express.RequestHandler {
let logDirectory = Container.getParameter('logDirectory');
// ensure log directory exists
fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory)
// create a rotating write stream
var accessLogStream = FileStreamRotator.getStream({
filename: logDirectory + path.sep + (config.get('log.file_format') || 'access-%DATE%.log'),
frequency: config.get('log.rotate.frequency') || 'daily',
verbose: config.get('log.verbose') || false
});
let skip: any = function() { return false };
if (config.get('log.skip') !== 'none') {
skip = function(req, res) {
return res.statusCode < Number(config.get('log.skip'));
};
}
return morgan('combined', {
stream: accessLogStream,
skip: skip
});
}
开发者ID:nicolanrizzo,项目名称:node-microframework,代码行数:26,代码来源:logger.ts
示例4: Promise
return new Promise((resolve, reject) => {
// we need to verify if we have a repository added and a server port
if (!options.repo) {
reject(new Error('The server must be started with a connected repository'))
}
if (!options.port) {
reject(new Error('The server must be started with an available port'))
}
// let's init a express app, and add some middlewares
const app = express();
const http = _http.createServer(app);
app.use(morgan('dev'));
app.use(helmet());
app.use((err, req, res, next) => {
reject(new Error('Something went wrong!, err:' + err));
res.status(500).send('Something went wrong!')
});
// we add our API's to the express app
traderChannelsAPI(app, options);
// finally we start the server, and return the newly created server
const server = app.listen(options.port, () => resolve(server))
})
开发者ID:Chegeek,项目名称:TradeJS,代码行数:26,代码来源:server.ts
示例5: callback
server.setConfig((app) => {
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(morgan('combined'));
app.use(cors({
origin: (origin, callback) => {
try {
let ok: boolean = config.originsWhitelist.indexOf(origin) !== -1
callback(null, ok);
} catch (e) {
callback(e, null);
}
}
}));
app.use(jwt({ secret: config.appSecret })
.unless({
path: ['/api/account/login', '/setup', '/',
{
url: '/api/donors',
methods: ['GET', 'POST']
}]
}));
let feed: DonorsFeed = kernel.get<DonorsFeed>(TYPES.DonorsFeed);
feed.start(httpServer);
});
开发者ID:kibiluzbad,项目名称:kamrusepa,代码行数:28,代码来源:server.ts
示例6: if
export let parserInit = ()=> {
app.use(favicon(path.resolve('favicon.ico')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
if (SERVER_CONFIG.env === DEV) {
app.use(logger(DEV));
var whitelist = ['http://127.0.0.1:3008','http://127.0.0.1:3006'];
var corsOptionsDelegate = function(req, callback){
var corsOptions;
if(whitelist.indexOf(req.header('Origin')) !== -1){
corsOptions = { origin: true ,credentials:true}; // reflect (enable) the requested origin in the CORS response
}else{
corsOptions = { origin: false }; // disable CORS for this request
}
callback(null, corsOptions); // callback expects two parameters: error and options
};
/*var corsOptions = {
origin: 'http://127.0.0.1:3008',
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
};*/
app.use(cors(corsOptionsDelegate));//white List
//app.options('http://127.0.0.1:3008', cors());//If allowed Access-Control-Allow-Originďź* Be sure to write
}
else if (SERVER_CONFIG.env === PROD) {
app.use(logger('prod'));
}
timeoutParser.init();
errParser.init();
parserInit = ()=> {
throw new Error("parsers/index.ts: parsers have been initialized.");
}
}
开发者ID:guoyu07,项目名称:react-node-cms,代码行数:33,代码来源:parserInit.ts
示例7: function
export default function () {
var app: express.Express = express();
for (let model of config.globFiles(config.models)) {
require(path.resolve(model));
}
if (config.useMongo) {
mongoose.connect(config.mongodb, {
promiseLibrary: global.Promise
}).catch(() => { console.log('Error connecting to mongos'); });
}
app.set('views', path.join(__dirname, '../../src/views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, '../../src/public')));
for (let route of config.globFiles(config.routes)) {
require(path.resolve(route)).default(app);
}
app.use((req: express.Request, res: express.Response, next: Function): void => {
let err: Error = new Error('Not Found');
next(err);
});
return app;
};
开发者ID:rjmacarthy,项目名称:express-typescript-starter,代码行数:33,代码来源:express.ts
示例8: config
/**
* Configure application
*
* @class Server
* @method config
* @return void
*/
private config() {
//configure jade
this.app.set("views", path.join(__dirname, "views"));
//this.app.set("view engine", "jade");
this.app.set("view engine", "ejs");
this.app.engine("html", require("ejs").renderFile);
//mount logger
this.app.use(logger("dev"));
//mount json form parser
this.app.use(bodyParser.json());
//mount query string parser
this.app.use(bodyParser.urlencoded({ extended: true }));
this.app.use(cookieParser());
//add static paths
this.app.use(express.static(path.join(__dirname, "public")));
this.app.use(express.static(path.join(__dirname, "bower_components")));
// catch 404 and forward to error handler
this.app.use(function(err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
let error: Error = new Error("Not Found");
err.status = 404;
next(err);
});
}
开发者ID:greenlakerod,项目名称:cribbage,代码行数:37,代码来源:app.ts
示例9: config
/**
* Configure application
*
* @class Server
* @method config
* @return void
*/
private config() {
//configure jade
this.app.set("views", path.join(__dirname, "views"));
this.app.set("view engine", "jade");
// uncomment after placing your favicon in /public
// this.app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
//mount logger
this.app.use(logger("dev"));
//mount json form parser
this.app.use(bodyParser.json());
//mount query string parser
this.app.use(bodyParser.urlencoded({ extended: true }));
//add static paths
this.app.use(express.static(path.join(__dirname, "public")));
this.app.use(express.static(path.join(__dirname, "bower_components")));
// catch 404 and forward to error handler
this.app.use(function(err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
var error = new Error("Not Found");
err.status = 404;
next(err);
});
}
开发者ID:kaveh981,项目名称:money_transfer,代码行数:36,代码来源:app.ts
示例10: config
/**
* Configures application
*
* @class Server
* @method config
* @return {void}
*/
public config(): void {
// mount query string parser
this.app.use(bodyParser.urlencoded({
extended: true
}))
// mount json form parser
this.app.use(bodyParser.json())
// mount cookie parker
this.app.use(cookieParser())
// mount logger
this.app.use(logger("dev"))
// mount compression
this.app.use(compression())
// mount helmet
this.app.use(helmet())
// mount cors
this.app.use(cors())
// cors
// this.app.use((req: Request, res: Response, next: NextFunction) => {
// res.header('Access-Control-Allow-Origin', 'http://localhost:8080')
// res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS, PURGE')
// res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Credentials')
// res.header('Access-Control-Allow-Credentials', 'true')
// next()
// })
}
开发者ID:yeegr,项目名称:SingularJS,代码行数:40,代码来源:server.ts
注:本文中的morgan类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论