express.static正在处理根URL请求.例如,我想从https://example.com到https://example.com/dashboard进行快速重定向.检查下面的情况,第一个工作,第二个不工作.我希望第二个也能奏效.谁知道为什么?
案例1(工程)
app.get('/', (req, res, next) => {
res.redirect('/dashboard');
})
app.use(express.static(path.join(__dirname, 'dist')))
app.get('/dashboard', (req, res, next) => {
//do stuff
})
Run Code Online (Sandbox Code Playgroud)
案例2(对我不起作用)
app.use(express.static(path.join(__dirname, 'dist')))
//request doesn't come here
app.get('/', (req, res, next) => {
res.redirect('/dashboard')
})
app.get('/dashboard', (req, res, next) => {
//do some stuff
})
Run Code Online (Sandbox Code Playgroud) 我在使用node-mysql2测试项目时遇到问题,做出反应,排序和开玩笑。仅在测试过程中会出现此问题。
Encoding not recognized: 'cesu8' (searched as: 'cesu8')
at Object.getCodec (project/node_modules/mysql2/node_modules/iconv-lite/lib/index.js:106:23)
at Object.getDecoder (project/node_modules/mysql2/node_modules/iconv-lite/lib/index.js:122:23)
at Object.<anonymous>.exports.decode (project/node_modules/mysql2/lib/parsers/string.js:9:23)
at Packet.Object.<anonymous>.Packet.readNullTerminatedString (project/node_modules/mysql2/lib/packets/packet.js:373:23)
at Function.Object.<anonymous>.Handshake.fromPacket (project/node_modules/mysql2/lib/packets/handshake.js:18:31)
at ClientHandshake.Object.<anonymous>.ClientHandshake.handshakeInit (project/node_modules/mysql2/lib/commands/client_handshake.js:98:38)
at ClientHandshake.Object.<anonymous>.Command.execute (project/node_modules/mysql2/lib/commands/command.js:40:20)
at Connection.Object.<anonymous>.Connection.handlePacket (project/node_modules/mysql2/lib/connection.js:515:28)
at PacketParser.onPacket (project/node_modules/mysql2/lib/connection.js:94:16)
at PacketParser.executeStart (project/node_modules/mysql2/lib/packet_parser.js:77:14)
at Socket.<anonymous> (project/node_modules/mysql2/lib/connection.js:102:29)
Run Code Online (Sandbox Code Playgroud) 我尝试在mingw上创建一个UDP套接字,但是socket()返回-1,使用errno = 0.奇怪.我已经包含了winsock2.h.最初我有编译错误undefined reference to socket@12,在设置
-lws2_32和-lwsock32Code :: Block的链接器设置后,编译成功.
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
RDF_LOG(kDEBUG, "sockfd %d ", sockfd);
if (sockfd < 0){
RDF_LOG(kERROR, "ERROR: %s , errno %d\n", strerror(errno), errno);
}
Run Code Online (Sandbox Code Playgroud)
结果 - > sockfd -1错误:没有错误,错误0
好的,我改为将RDF_LOG更改为fprintf.
int tmp = 0;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
tmp = errno;
fprintf(stderr, "sockfd %d ", sockfd);
if (sockfd < 0){
fprintf(stderr, "socket: %s , errno %d\n", strerror(tmp), tmp);
}
Run Code Online (Sandbox Code Playgroud)
返回的结果仍然是 - …
无法让智能感知为 .ts 文件工作。
测试.js
var http = require('http');
http.[intellisense available]
Run Code Online (Sandbox Code Playgroud)
测试文件
var http = require('http');
http.[no suggestions]
Run Code Online (Sandbox Code Playgroud)
似乎没有在阅读 index.d.ts
这是tsconfig.json:
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"watch": true
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议。真的很想使用打字稿,但在学习节点时需要提示。最好不要使用 javascript。
谢谢。
我有一个文件myhj.txt,我从cmd使用此命令隐藏了该文件attrib +h +s +r myhj.txt.现在我无法fopen()在C中打开带有标准功能的文件,所以我决定使用不返回错误的GetFileAttributes()函数.根据MSDN,当函数成功时,返回值是File Attribute Constants
当程序试图在printf()下面运行时,我不知道如何获取它们的值.当文件被隐藏时它也会稳定工作吗?如何使用其所有值访问隐藏文件?
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
FILE *log;
int main(int argc, char *argv[]) {
if(GetFileAttributes("myhj.txt") == INVALID_FILE_ATTRIBUTES){
printf("invalid get last error %d", GetLastError());
}else{
printf("%s", FILE_ATTRIBUTE_DIRECTORY);
}
}
Run Code Online (Sandbox Code Playgroud) node.js ×3
attributes ×1
c ×1
codeblocks ×1
express ×1
file ×1
hidden ×1
intellisense ×1
jestjs ×1
mingw ×1
node-mysql2 ×1
sockets ×1
typescript ×1
winapi ×1
windows ×1
winsock2 ×1