All Projects → thinkjs → think-trace

thinkjs / think-trace

Licence: MIT License
Error trace for ThinkJS 3.x

Programming Languages

HTML
75241 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to think-trace

Mortar
Mortar is a GO framework/library for building gRPC (and REST) web services.
Stars: ✭ 492 (+4000%)
Mutual labels:  middleware, trace
polix
🚀 Node.js Web Framework
Stars: ✭ 32 (+166.67%)
Mutual labels:  middleware, koa2
Koa Webpack
Development and Hot Reload Middleware for Koa2
Stars: ✭ 429 (+3475%)
Mutual labels:  middleware, koa2
Koa Helmet
Important security headers for koa
Stars: ✭ 595 (+4858.33%)
Mutual labels:  middleware, koa2
Egg Authz
egg-authz is an authorization middleware for Egg.js based on Casbin
Stars: ✭ 50 (+316.67%)
Mutual labels:  middleware, koa2
Koa Hbs
Handlebars templates for Koa.js
Stars: ✭ 156 (+1200%)
Mutual labels:  middleware, koa2
Koatty
Koa2 + Typescript = Koatty. Use Typescript's decorator implement IOC and AOP.
Stars: ✭ 67 (+458.33%)
Mutual labels:  middleware, koa2
koa-rest-router
Most powerful, flexible and composable router for building enterprise RESTful APIs easily!
Stars: ✭ 67 (+458.33%)
Mutual labels:  middleware, koa2
dictator
Dictates what your users see. Plug-based authorization.
Stars: ✭ 77 (+541.67%)
Mutual labels:  middleware
Agile-Server
A simple, fast, complete Node.js server solution, based on KOA. 简单快速的 、性能强劲的、功能齐全的 node 服务器解决方案合集,基于 KOA。
Stars: ✭ 24 (+100%)
Mutual labels:  koa2
login push
vue+koa2+jwt实现单点登录 + todolist增删改查
Stars: ✭ 20 (+66.67%)
Mutual labels:  koa2
use
Easily add plugin support to your node.js application.
Stars: ✭ 25 (+108.33%)
Mutual labels:  middleware
node-uploadx
Node.js middleware for handling resumable uploads
Stars: ✭ 17 (+41.67%)
Mutual labels:  middleware
request-context
Simple connect middleware for accessing data in a request context.
Stars: ✭ 55 (+358.33%)
Mutual labels:  middleware
geggleto-acl
PSR-7 Zend ACL implementation - Permission Library [ slim, psr7, acl, permissions, zend ]
Stars: ✭ 33 (+175%)
Mutual labels:  middleware
zipkin-cpp-opentracing
OpenTracing Tracer implementation for Zipkin in C++
Stars: ✭ 46 (+283.33%)
Mutual labels:  trace
dotnet-monitor-ui
This project is created as an easy to access user experience for dotnet-monitor tool which can be found here. dotnet-monitor is on demand tool which can be used on .NET Core applications to get memory dumps, traces and metrics of a running application.
Stars: ✭ 38 (+216.67%)
Mutual labels:  trace
restana
Super fast and minimalist framework for building REST micro-services.
Stars: ✭ 380 (+3066.67%)
Mutual labels:  middleware
access-log
PSR-15 middleware to generate access logs
Stars: ✭ 21 (+75%)
Mutual labels:  middleware
falcon-policy
Policy Middleware for Falcon APIs
Stars: ✭ 30 (+150%)
Mutual labels:  middleware

think-trace

npm Travis Coveralls David

think-trace is an error handler for ThinkJS 3.x and koa2. It provides a pretty error web interface that helps you debug your web project.

Installation

npm install think-trace

How To Use

Koa2

const traceMiddleware = require('think-trace');
app.use(traceMiddleware({
  sourceMap: false,
  error: err => console.error(err)
}));

ThinkJS3.x

Modify src/config/middleware.js:

const trace = require('think-trace');

module.exports = [
  {
    handle: trace, 
    options: {
      sourceMap: false,
      error(err, ctx) {
        return console.error(err);
      }
    }
  }
];

Options

  • sourceMap: Whether your project has source map support, default is true.
  • debug: Whether show error detail in web, default is true.
  • ctxLineNumbers: How long you want show error line context, default is 10.
  • contentType: Due to think-trace can't get content-type while application throw error, you should set content type by yourself by this parameter. Default value is ctx => 'html';. You can set json content type like this:
    {
      contentType(ctx) {
        // All request url starts of /api or request header contains `X-Requested-With: XMLHttpRequest` will output json error
        const APIRequest = /^\/api/.test(ctx.request.path);
        const AJAXRequest = ctx.is('X-Requested-With', 'XMLHttpRequest');
        
        return APIRequest || AJAXRequest ? 'json' : 'html';
      }
    }
  • error: callback function when catch error, it receives Error object and ctx as parameter.
  • templates: error status template path, if you want to specific. You can set templates as a path string, then module will read all status file named like 404.html, 502.html as your customed status page. Or you can set templates as an object, for example:
    {
      options: {
        //basic set as string, then put 404.html, 500.html into error folder
        templates: path.join(__dirname, 'error'),
    
        //customed set as object
        templates: {
          404: path.join(__dirname, 'error/404.html'),
          500: path.join(__dirname, 'error/500.html'),
          502: path.join(__dirname, 'error/502.html')
        }
      }
    }
    Also you can set templates as function, function should return error template file path or error template file path object.

Contributing

Contributions welcome!

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].