我的路由处理程序意外返回502 Bad Gateway
。然后我注意到.js文件中仍然存在旧处理程序中途返回的内容:
// the target .js file
express.get("/authorizationRequestor", (req, res) => {
console.log(`=====/authorizationRequestor 2.4 begin=====`);
const shopParam = req.query.shop;
if (!shopParam)
return res.status(400).send("No shop param specified");
const state = nonce();
const installShopUrl = buildInstallUrl(shopParam, state, getRedirectUri());
console.log(state, `=====state=====`);
console.log(installShopUrl, `=====installShopUrl=====`);
return;
res.cookie("state", state);
// redirect browser to the scopes page for front channel permission granting
console.log(res, `=====authorizationRequestor res / end=====`);
res.redirect(installShopUrl);
});
// the updated .ts file
express.get("/authorizationRequestor/", (req: Request, res: Response): Response|void => {
console.log(`=====/authorizationRequestor/ 2.5 begin=====`);
const shopParam = req.query.shop;
if (!shopParam) return res.status(400).send("No shop param specified");
const state = nonce();
const installShopUrl = buildInstallUrl(shopParam, state, getRedirectUri());
res.cookie("state", state);
// redirect browser to the scopes page for front channel permission granting
console.log(`=====/auth...requestor end=====`);
res.redirect(installShopUrl);
});
重新运行tsc之后,没有任何变化。 tsc --watch
(IDE中的TSLint)也表明.ts文件中没有错误:
[1:40:09 PM] File change detected. Starting incremental compilation...
[1:40:09 PM] Found 0 errors. Watching for file changes.
我将noEmit显式设置为false。还有什么其他原因可能导致更新现在失败?我所做的最后一个更改是将resolveJsonModule设置为true,由于导入JSON文件,我现在需要使用它:
// tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": false,
"outDir": "outDir",
"sourceMap": true,
"strict": true,
"target": "es2017",
"esModuleInterop" : true,
"noEmit" : false,
"resolveJsonModule" : true
},
"compileOnSave": true,
"include": [
"src"
]
}
更新
注释resolveJsonModule
并将关联的文件导入index.ts可以解决编译问题。如果有人知道更好的解决方案,我仍然想使用此设置。