-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (54 loc) · 1.61 KB
/
app.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const http = require('http')
const fs = require('fs');
const path = require('path')
const options = {
hostname: '127.0.0.1',
port: 3000,
path: '/',
method: 'GET'
}
const express = require('express'),
app = express();
// const req = http.request(options, res => {
// console.log(`statusCode:${res.statusCode}`)
// res.on('data', d => {
// process.stdout.write(d)
// })
// })
// const server = http.createServer((req, res) => {
// // var url = req.url.endsWith('/')? req.url + "index.html" : req.url;
// var url = path.join(__dirname, "index.html")
// console.log(url)
// console.log(fs.existsSync(url))
// if(fs.existsSync(url))
// fs.readFile(url, (err, data) => {
// console.log(data)
// if(!err){
// res.writeHead(200, {"Content-Type": ""});
// res.end(data);
// }
// })
// })
app.get('/', (req, res) => {
console.log(`Incoming connection from ${req.ip}, hostname [${req.hostname}]`);
var url = path.join(__dirname, "public/index.html");
if(fs.existsSync(url)){
fs.readFile(url, (err, data) => {
if(!err){
res.writeHead(200, {"Content-Type": ""});
res.end(data);
}
})
}
})
//MIDDLEWARE
app.use("/assets", express.static(__dirname + '/public'));
app.use("/", express.static(__dirname + '/public'));
// app.use("/style",express.static(__dirname + '/public/style'));
// app.use("/fonts",express.static(__dirname + '/public/fonts'));
// app.use("/img",express.static(__dirname + '/public/img'));
// app.use("/js",express.static(__dirname + '/public/js'));
const port = process.env.PORT||3000
app.listen(port, ()=>{
console.log(`Server running at port ${port}[${new Date()}]`)
})