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


TypeScript errorhandler.default函數代碼示例

本文整理匯總了TypeScript中errorhandler.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了default函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

import errorHandler from "errorhandler";
import app from "./app";
import logger from "./util/logger";

if (app.get("env") === "development") {
  app.use(errorHandler());
}

const server = app.listen(app.get("port"), () => {
  logger.info(
    "  App is running at http://localhost:%d in %s mode",
    app.get("port"),
    app.get("env"),
  );
  logger.info("  Press CTRL-C to stop\n");
});

export default server;
開發者ID:klakovsky,項目名稱:blank-nt-post,代碼行數:18,代碼來源:server.ts

示例2: configure

function configure(server: express.Application): void {
    server.use(errorHandler());

    configuration.http_address = "0.0.0.0";
    configuration.http_port = process.env.PORT;
    configuration.databaseName = process.env.MONGODB_URL;

    configuration.githubApplication.scope = ["user", "public_repo"];
    configuration.githubApplication.dnsName = process.env.HTTP_ADDRESS;
}
開發者ID:ciuliot,項目名稱:github-tracker,代碼行數:10,代碼來源:heroku.ts

示例3: configure

function configure(server: express.Application): void {
    server.use(errorHandler());

    configuration.http_address = process.env.OPENSHIFT_NODEJS_IP;
    configuration.http_port = process.env.OPENSHIFT_NODEJS_PORT;
    configuration.databaseName = util.format("%sgittrack", process.env.OPENSHIFT_MONGODB_DB_URL);

    configuration.githubApplication.scope = ["user", "public_repo"];
    configuration.githubApplication.dnsName = process.env.OPENSHIFT_APP_DNS;
}
開發者ID:ciuliot,項目名稱:github-tracker,代碼行數:10,代碼來源:openshift.ts

示例4: config

  private config() {
    this.app.use(bodyParser.json())
    this.app.use(bodyParser.urlencoded({ extended: true }))

    this.app.use(cors())
    this.app.use(compression())

    this.app.use((err: any, req, res, next) => {
      err.status = 404
      next(err)
    })

    this.app.use(errorHandler())
  }
開發者ID:magic8bot,項目名稱:magic8bot,代碼行數:14,代碼來源:server.ts

示例5: usePlugins

 private usePlugins(): void {
     this.app.use(morgan(":method :url :status - :response-time ms"));
     if (config.get("isDev")) {
         this.app.use(errorhandler());
     }
     this.app.use(cors());
     this.app.use(bodyParser.urlencoded({extended: true}));
     this.app.use(bodyParser.json());
     this.app.use(expressValidator());
     this.app.use(compression());
     if(config.get("isDev")) {
         this.app.use(express.static(path.join(__dirname, "public")));
     }else{
         this.app.use(express.static(path.join(__dirname, "public"), {maxAge: "10h"}));
     }
     this.app.use(auth());
     this.app.use(favicon(path.join(__dirname, "/public/favicon.ico")));
     logs.info("App configured");
 }
開發者ID:ZulusK,項目名稱:Budgetarium,代碼行數:19,代碼來源:App.ts

示例6: function

    //cookie: { secure: true } //?invalid csrf token?
}));
var sessionCheck = function(req, res, next) {
    if (req.session.login === true) {
        next();
    } else {
        res.redirect('/login');
    }
};
app.use(express.static(__dirname + '/public'));
app.use('/exam_images', express.static(c.image_dir));
app.use('/figures', express.static(c.figure_dir));

// development only
if ('development' == app.get('env')) {
    app.use(errorhandler());
}

app.get("/", sessionCheck, routes.index);
app.post("/", index_post.index);
app.get("/login", login.index);
app.post('/login', login_post.index);
app.get("/logout", logout.index);
app.get("/result/:exam_id", result.index);
app.get("/images", images.index);
app.get("/image_folder", image_folder.index);
app.get("/search", search.index);
app.post("/search", search_post.index);

process.on('uncaughtException', function(err) {
    console.log(err);
開發者ID:KoichiHirahata,項目名稱:FindingsSite,代碼行數:31,代碼來源:server.ts

示例7: BmaApi

  createServersAndListen: async (name:string, server:Server, interfaces:NetworkInterface[], httpLogs:boolean, logger:any, staticPath:string|null, routingCallback:any, listenWebSocket:any, enableFileUpload:boolean = false) => {

    const app = express();

    // all environments
    if (httpLogs) {
      app.use(morgan('\x1b[90m:remote-addr - :method :url HTTP/:http-version :status :res[content-length] - :response-time ms\x1b[0m', {
        stream: {
          write: function(message:string){
            message && logger && logger.trace(message.replace(/\n$/,''));
          }
        }
      }));
    }

    // DDOS protection
    const whitelist = interfaces.map(i => i.ip);
    if (whitelist.indexOf('127.0.0.1') === -1) {
      whitelist.push('127.0.0.1');
    }
    const ddosConf = server.conf.dos || {};
    ddosConf.silentStart = true
    ddosConf.whitelist = _.uniq((ddosConf.whitelist || []).concat(whitelist));
    const ddosInstance = new ddos(ddosConf);
    app.use(ddosInstance.express);

    // CORS for **any** HTTP request
    app.use(cors());

    if (enableFileUpload) {
      // File upload for backup API
      app.use(fileUpload());
    }

    app.use(bodyParser.urlencoded({
      extended: true
    }));
    app.use(bodyParser.json({ limit: '10mb' }));

    // development only
    if (app.get('env') == 'development') {
      app.use(errorhandler());
    }

    const handleRequest = (method:any, uri:string, promiseFunc:(...args:any[])=>Promise<any>, theLimiter:any) => {
      const limiter = theLimiter || BMALimitation.limitAsUnlimited();
      method(uri, async function(req:any, res:any) {
        res.set('Access-Control-Allow-Origin', '*');
        res.type('application/json');
        try {
          if (!limiter.canAnswerNow()) {
            throw BMAConstants.ERRORS.HTTP_LIMITATION;
          }
          limiter.processRequest();
          let result = await promiseFunc(req);
          // HTTP answer
          res.status(200).send(JSON.stringify(result, null, "  "));
        } catch (e) {
          let error = getResultingError(e, logger);
          // HTTP error
          res.status(error.httpCode).send(JSON.stringify(error.uerr, null, "  "));
        }
      });
    };

    const handleFileRequest = (method:any, uri:string, promiseFunc:(...args:any[])=>Promise<any>, theLimiter:any) => {
      const limiter = theLimiter || BMALimitation.limitAsUnlimited();
      method(uri, async function(req:any, res:any) {
        res.set('Access-Control-Allow-Origin', '*');
        try {
          if (!limiter.canAnswerNow()) {
            throw BMAConstants.ERRORS.HTTP_LIMITATION;
          }
          limiter.processRequest();
          let fileStream:any = await promiseFunc(req);
          // HTTP answer
          fileStream.pipe(res);
        } catch (e) {
          let error = getResultingError(e, logger);
          // HTTP error
          res.status(error.httpCode).send(JSON.stringify(error.uerr, null, "  "));
          throw e
        }
      });
    };

    routingCallback(app, {
      httpGET:     (uri:string, promiseFunc:(...args:any[])=>Promise<any>, limiter:any) => handleRequest(app.get.bind(app), uri, promiseFunc, limiter),
      httpPOST:    (uri:string, promiseFunc:(...args:any[])=>Promise<any>, limiter:any) => handleRequest(app.post.bind(app), uri, promiseFunc, limiter),
      httpGETFile: (uri:string, promiseFunc:(...args:any[])=>Promise<any>, limiter:any) => handleFileRequest(app.get.bind(app), uri, promiseFunc, limiter)
    });

    if (staticPath) {
      app.use(express.static(staticPath));
    }

    const httpServers = interfaces.map(() => {
      const httpServer = http.createServer(app);
      const sockets:any = {};
      let nextSocketId = 0;
//.........這裏部分代碼省略.........
開發者ID:Kalmac,項目名稱:duniter,代碼行數:101,代碼來源:network.ts

示例8: function

// Catch All
app.use(express.static(__dirname + '/public'));
app.use(function (req: express.Request, res: express.Response, next) {
    res.status(404);
    if (req.accepts('html')) {
        res.render('_shared/404');
        return;
    }
    if (req.accepts('json')) {
        res.send({ error: 'Not found' });
        return;
    }
    res.type('txt').send('Not found');
});
app.use(errorhandler({ dumpExceptions: true, showStack: true }));


// Start the server
var httpServer = http.createServer(app);

io = io.listen(httpServer);
io.set('log level', 1);

httpServer.listen(1337); // use 0 to assign random port
httpServer.on('listening', function () {
    console.log('listening on port: ', httpServer.address().port);
});

// var httpsServer = https.createServer(options, app);
// httpsServer.listen(443);
開發者ID:irysius,項目名稱:NodeSiteTemplate,代碼行數:30,代碼來源:app.ts

示例9: configure

function configure(server: express.Application) {
    server.use(errorHandler({ dumpExceptions: true, showStack: true }));
}
開發者ID:ciuliot,項目名稱:github-tracker,代碼行數:3,代碼來源:development.ts


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