res-res-1
v1.0.0
Published
```javascript const fs = require('fs'); const http = require('http'); const path = require('path');
Downloads
1
Readme
请求路径
const fs = require('fs');
const http = require('http');
const path = require('path');
res.setHeader('Content-type','text/html;charset = utf-8');
const static = 'public';
//获取请求路径
let pathname = url.parse(req.url).pathname;
//判断访问的是不是根路径
if(pathname === '/'){
pathname = 'index.html';
}
//区分是不是静态路径
if(path.extname(pathname)){
//是静态资源
if(fs.existsSync(path.join(static,pathname))){
res.end(fs.readFileSync(path.join(static,pathname)));
}else{
res.end(fs.readFileSync('publice/404.html'));
}
}else{
//是接口
if(pathname === '/12345678'){
res.end('hhhhh');
}
res.end('api 找不到');
}