node创建一个http服务——代码块
作者:ailion
发布时间:2022-07-15 10:04
0人已阅读
简介:
/** * Created by admin on 2020/11/25. */ /*创建一个http服务器*/ const express = require("express") const app = express() const http = require('http') const fs = require('fs') const path = require('path') const port = 3000 // 配置允许访问问价夹 app.use(express.static(path.resolve(__dirname, './dist'))) app.get('*', function(req, res) { const html = fs.readFileSync(path.resolve(__dirname, './dist/index.html'), 'utf-8') res.send(html) }) http.createServer(app).listen(port,()=>{ console.log(`服务器正在运行http://localhost:${port}`); })
写下您的评论...
评论