-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (34 loc) · 1.07 KB
/
server.js
File metadata and controls
39 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var express = require('express')
// var path = require('path')
var app = express()
// app.use(serveStatic(path.join(__dirname, 'web')))
// app.use(express.static(path.join(__dirname, '/web/assets/')));
app.use(express.static('web'))
app.get('/',function(req,res){
res.sendFile(__dirname+'/web/index.html');
})
app.listen(3000)
/*
const http = require('http');
const fs = require('fs');
const serveStatic = require('serve-static');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
// res.statusCode = 200;
// res.setHeader('Content-Type', 'text/plain');
// res.end('Hello World!\n');
// fs.readFile('./web/index.html', function (err, data) {
// if (err) throw err;
// res.writeHead(200, { 'Content_Type': 'text/html' });
// res.write(data.toString());
// res.end()
// })
fs.readdir('./web/',function(err,file){
serveStatic('web',{'index':file})
})
});
server.listen(port, hostname, () => {
console.log(`服务器运行在 http://${hostname}:${port}/`);
});
*/