mirror of https://github.com/boa-dev/boa.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
775 B
24 lines
775 B
2 years ago
|
import { createServer } from "http";
|
||
|
import { readFile, readFileSync } from "fs";
|
||
|
import { dirname, join } from "path";
|
||
|
import { fileURLToPath, parse } from "url";
|
||
|
import { lookup } from "mime-types";
|
||
|
|
||
|
const __filename = fileURLToPath(import.meta.url);
|
||
|
|
||
|
createServer((req, res) => {
|
||
|
const __dirname = dirname(__filename);
|
||
1 year ago
|
const path = join(__dirname, "../../../dist", parse(req.url, true).path);
|
||
2 years ago
|
readFile(path, (err, data) => {
|
||
|
if (err) {
|
||
|
res.writeHead(200, { "Content-Type": "text/html" });
|
||
1 year ago
|
res.end(readFileSync(join(__dirname, "../../../dist/index.html")));
|
||
2 years ago
|
} else {
|
||
|
res.writeHead(200, { "Content-Type": lookup(path) });
|
||
|
res.end(data);
|
||
|
}
|
||
|
});
|
||
|
}).listen(8081, () => {
|
||
|
console.log("Server running at http://localhost:8081/");
|
||
|
});
|