我一直在为url缩短器做一个项目,每当有人点击该api或有人提出views请求时,我都会尝试增加get。我不知道哪里出了问题,但这些观点只是在增加一次而已。

下面是我编写的代码,用于每次发出get请求时增加视图。
我不知道出了什么问题,,我已经搜索了很多论坛,堆栈溢出,文章已经问过问题了。
Note -
views的默认值是0,这里是post请求中的值。,这是文件树
├── LICENSE
├── README.md
├── client
│ ├── assets
│ │ ├── bg.svg
│ │ ├── favicon
│ │ │ └── favicon.ico
│ │ └── fonts
│ │ ├── Apercu\ Medium.woff
│ │ ├── Apercu\ Mono.woff
│ │ └── Apercu_Regular.woff
│ ├── css
│ │ └── style.css
│ ├── index.html
│ └── js
│ └── script.js
├── index.js
├── models
│ ├── admin_model.js
│ └── urlshorten.js
├── package-lock.json
├── package.json
├── routes
│ ├── admin.js
│ ├── auth.js
│ ├── custom.js
│ ├── stats.js
│ └── urlShorten.js
├── static
│ ├── css
│ │ └── style.css
│ ├── favicon.ico
│ ├── fonts
│ │ └── Inter-Regular.woff
│ └── urlshort.gif
└── views
├── index.pug
└── script.js发布于 2019-10-17 09:09:21
简单地说:
1. It is because of 301 Status Code for Redirect you are using.
2. 301 Status Code represents a Permanent Redirect.
3. The browser stores the main URL in the memory.
4. The next time you request the short link from your browser, it gets the Original
URL from its memory and sends you there, without going through the Server.
5. Since the request doesn't go through the server, the server fails to increment it.解决方案:
将301 (永久)状态代码更改为307 (临时)状态代码。
FILE: ShortLink/routes/urlShortner.js
Change the below lines
Line 37: res.writeHead(301, {
Line 38: Location: url.inputUrl
Line 39: });
to
Line 37: res.writeHead(307, {
Line 38: Location: url.inputUrl
Line 39: });我还创建了一个拉的请求,您可以验证你的Github回购。
https://stackoverflow.com/questions/58428329
复制相似问题