{"size": 972, "ext": "js", "max_stars_repo_path": "src/helper/server.js", "max_stars_repo_name": "jeddygong/anystatic", "max_stars_repo_stars_event_min_datetime": "2020-12-02T01:56:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T01:56:28.000Z", "max_issues_repo_path": "src/helper/server.js", "max_issues_repo_name": "jeddygong/anystatic", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/helper/server.js", "max_forks_repo_name": "jeddygong/anystatic", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.1304347826, "max_line_length": 71, "alphanum_fraction": 0.6440329218}
/*
 * @Description:
 * @Author: Jeddy
 * @Date: 2020-07-14 22:14:59
 * @LastEditors: Jeddy
 * @LastEditTime: 2020-12-02 23:25:31
 */

const http = require("http");
const chalk = require("chalk");
const path = require("path");
const route = require("./route");
const openBrowser = require("./openBrowser");

const conf = require("./../config/defaultConfig");

class Server {
	constructor (configs) {
		this.configs = Object.assign({}, conf, configs);
		// console.log(this.configs);
	}

	start () {
		const server = http.createServer((req, res) => {
			// root: 当前工作的目录路径 , 当前的路径;
			// return 返回整个路径
			const filePath = path.join(this.configs.root, req.url);

			route(req, res, filePath, this.configs);

		});

		server.listen(this.configs.port, this.configs.hostname, () => {
			const addr = `http://${this.configs.hostname}:${this.configs.port}`;
			console.info(`Server started at ${chalk.green(addr)}`);
			openBrowser(addr);
		});
	}
}

module.exports = Server;




