Coder Social home page Coder Social logo

wxtoken's People

Watchers

 avatar

wxtoken's Issues

优化建议

有几个问题,你可以优化下的:

1. Token类

方法应尽量定义在prototype里面,现在你大部分写在Token那个构造函数里面了,扣性能细节的话会影响Token类的实例化性能

2. 刷新缓存的策略

现在用了轮询检查刷新的方法,其实可以不用轮询的。每次从服务端获取Token的时候,

2.1 看是否有文件缓存

2.2 如果没有,则从服务器端获取,并存入缓存

2.3 如果有,拿(当前时间戳 - 已缓存的Token的时间戳),看是否超出过期时间

2.3.1 如果超出过期时间,进入2.2

2.3.2 如果没过期,直接返回缓存的Token

3. auth.js 不属于路由

新建一个utils的目录,将auth.js放到utils目录下

4. 新建一个configs/config.js文件

配置类型的信息都可以放config.js中
即将 APPID和APPSECRET抽到config.js中

module.exports = {
    APPID: process.env.APP_ID
    APPSECRET: process.env.APP_SECRET
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.