當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript morgan.default函數代碼示例

本文整理匯總了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");
}
開發者ID:ciuliot,項目名稱:github-tracker,代碼行數:65,代碼來源:all.ts

示例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'));
開發者ID:overpower-doublej,項目名稱:gcm-server-test,代碼行數:31,代碼來源:app.ts

示例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);
開發者ID:soramusoka,項目名稱:timeline-project,代碼行數:31,代碼來源:runserver.ts

示例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);
開發者ID:thekj,項目名稱:berlin_sandbox,代碼行數:31,代碼來源:app.ts

示例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;
開發者ID:poomugam,項目名稱:smart-quiz,代碼行數:30,代碼來源:server.ts

示例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,
//.........這裏部分代碼省略.........
開發者ID:tjxn,項目名稱:CharBroiled,代碼行數:101,代碼來源:app.ts

示例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;
};
開發者ID:MisterTea,項目名稱:TidalWave,代碼行數:88,代碼來源:app-handler.ts

示例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);
開發者ID:jlamby,項目名稱:nicobot-persistence,代碼行數:31,代碼來源:main.ts

示例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}`));
開發者ID:zaeleus,項目名稱:lp-api,代碼行數:30,代碼來源:index.ts

示例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
開發者ID:rymizuki,項目名稱:site-animechannel,代碼行數:31,代碼來源:app.ts


注:本文中的morgan.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。