yycvip 发表于 5 天前

推荐几种快速搭建轻量级Web服务的实现!

Python内置http

python -m http.server 端口
优点
零配置、无需安装依赖


缺点
单线程、性能差、无路由功能


场景
实现本地快速共享文件,例如想给同事发一个大文件,但是超过微信限制大小,那我们就可以用这种方式搭建一个web服务,供别人下载查看。

Node.js

npx http-server ./dist -p 8000
优点
支持SPA路由、热更新
缺点
需Node环境
场景
前端人员做完一个静态页面,想给领导预览

Express

const express = require('express');
const app = express();
app.use(express.static('public')); // 静态文件
app.listen(8000);
优点
中间件生态、REST API支持
缺点
有技术门槛,需要有js基础知识

Nginx

server {
    listen 8000;
    root /path/to/dist; # 前端构建目录
    index index.html;
    location / {
      try_files $uri $uri/ /index.html; # SPA路由支持
    }
}启动命令

nginx -c /path/to/nginx.conf

页: [1]
查看完整版本: 推荐几种快速搭建轻量级Web服务的实现!