本文整理匯總了TypeScript中errorhandler.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript errorhandler.default方法的具體用法?TypeScript errorhandler.default怎麽用?TypeScript errorhandler.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類errorhandler
的用法示例。
在下文中一共展示了errorhandler.default方法的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
}
}
示例2: error
export default function error(): any {
if (process.env.NODE_ENV !== "development") {
return defaultRoutes.error500;
} else {
return errorhandler();
}
}
示例3: function
export default function(app) {
let rootPath = path.normalize(`${__dirname}/../..`);
let clientPath: string = path.join(rootPath, 'client');
app.use(express.static(clientPath));
app.set('clientPath', clientPath);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(methodOverride());
// let env = app.get('env');
let env = process.env.NODE_ENV || 'development';
if (env === 'development') {
app.use(errorHandler());
}
}
示例4: newInstance
newInstance(config: IConfig, env: string): express.Express {
var app = express();
app.set("views", config.root + "/server/views");
app.set("view engine", "html");
app.use(compression());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(cookieParser());
// Persist sessions with mongoStore / sequelizeStore
// We need to enable sessions for passport-twitter because it"s an
// oauth 1.0 strategy, and Lusca depends on sessions
/*app.use(session({
secret: config.secrets.session,
saveUninitialized: true,
resave: false,
store: new mongoStore({
mongooseConnection: mongoose.connection,
db: "opcrates-bot-server"
})
}));*/
app.set("appPath", path.join(config.root, "client"));
app.use(morgan("dev"));
app.use(express.static(app.get("appPath")));
if ("development" === env || "test" === env) {
app.use(express.static(path.join(config.root, ".tmp")));
app.use(errorHandler()); // Error handler - has to be last
}
return app;
}
示例5: config
private config() {
const app = this.app;
const port = this.normalizePort(process.env.PORT || this.port);
// set server port
app.set('port', port);
// 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(this.logLevel));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
app.use(cors());
app.use(express.static(path.resolve(__dirname + '/client/statics')));
if (process.env.NODE_ENV === 'development') {
// only use in development
app.use(errorhandler({
log: (err, str, req) => this.errorNotification(err, str, req)
}));
}
}
示例6: config
/**
* Configure application
*
* @class Server
* @method config
*/
public config() {
//add static paths
this.app.use(express.static(path.join(__dirname, "public")));
//configure pug
this.app.set("views", path.join(__dirname, "views"));
this.app.set("view engine", "pug");
//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
}));
//mount cookie parser middleware
this.app.use(cookieParser("SECRET_GOES_HERE"));
// catch 404 and forward to error handler
this.app.use(function(err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
err.status = 404;
next(err);
});
//error handling
this.app.use(errorHandler());
}
示例7: errorHandler
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
if (app.get('env') === 'development') {
let errHandler = errorHandler();
errHandler(err, req, res, next);
} else {
res.send(500);
}
});
示例8: Error
export let init=()=>{
if(SERVER_CONFIG.env==DEV){
app.use(errorHandler({log:errorNotification}));
}
init=()=>{
throw new Error('timeout-parser.ts: Timeout parser has been initialized.');
}
};
示例9: config
config(router: Express.Router) {
var app = Express();
app.use((req, res, next) => {
console.log("middleware function called");
next();
})
app.use(BodyParser.urlencoded({ extended: false }));
app.use(BodyParser.json());
app.use(CookieParser());
app.use(router);
app.use(morgan("combined", { "stream": { write: (message) => { Logger.info(message) } } }));
if (process.env.NODE_ENV === 'dev') {
app.use(errorhandler());
}
return app;
}
示例10: express
sampler.pushSome(task);
} else {
nextTask = task;
}
}
return {
task: sampler ? sampler[0] : nextTask,
numCompleted: _.size(completedTasks),
numTotal,
}
}
const app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(errorhandler());
app.use(express.static(path.resolve(staticDir)));
app.get('/', utils.wrapPromise(async (req, res) => {
const nextTask = await getNextTask();
if (nextTask.task) {
console.log(nextTask.task);
const html = await renderTemplate(nextTask);
res.send(html);
} else {
res.send('DONE');
process.exit(0);
}
}));
app.post('/submit', utils.wrapPromise(async (req, res) => {