-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (24 loc) · 780 Bytes
/
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
const http = require("http");
const path = require("path");
const chalk = require("chalk");
const route = require("./src/helper/route");
const openurl = require("./src/helper/openurl");
const conf = require("./src/config/defaultConfig")
class Server {
constructor(config) {
this.conf = Object.assign({}, conf, config);
}
start() {
const server = http.createServer((req, res) => {
const url = req.url;
const filePath = path.join(conf.root, url);
route(req, res, filePath,this.conf);
})
server.listen(this.conf.port, this.conf.hostname, () => {
const addr = `http://${this.conf.hostname}:${this.conf.port}`;
console.log(`Server running at ${chalk.green(addr)}`);
openurl(addr)
})
}
}
module.exports = Server;