jwt.verify(token, dotenv.parsed.SECRET_KEY, function(err, decoded) { console.log('decoded ? ', decoded); if (decoded) { next(); } else { console.log("login first!"); return next({ status: 401, message: 'Please log in first!' }); } });
public loadConfig(): void { // 避免重复加载 if (this.cache) { return; } // 如果是生产环境,一些所需的信息会通过CI工具注入到process.env中 if (this.mode === 'production') { this.cache = process.env; return; } // 本地开发环境,需要读取项目目录中的 .env 文件 const filepath = path.join(__dirname, '..', '.env'); if (!fs.existsSync(filepath)) { throw new Error(`Please create configuration file: ${filepath}`); } const localEnv = dotenv.config({ path: filepath }).parsed; this.cache = { ...process.env, ...localEnv, }; }
public loadConfig(): void { // 避免重复加载 if (this.cache) { return; } // 如果是生产环境,一些所需的信息会通过CI工具注入到process.env中 if (this.mode === 'production') { this.cache = process.env; return; } // 本地开发环境,需要读取项目目录中的 .env 文件 const filepath = path.join(__dirname, '..', '.env'); if (!fs.existsSync(filepath)) { throw new Error(`Please create configuration file: ${filepath}`); } const localEnv = dotenv.config({ path: filepath }).parsed; this.cache = { ...process.env, ...localEnv, }; }