aboutsummaryrefslogtreecommitdiff
path: root/test/bundler/integration/vue/serve.mjs
blob: acaaeea5821305fbf6e760acd53577b1764cbf90 (plain) (blame)
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
import * as http from "http";
import * as fs from "fs";

const distDir = process.argv[2];
if (!distDir) {
  throw new Error(".");
}

const server = http.createServer((req, res) => {
  if (req.url === "/") {
    res.writeHead(200, { "Content-Type": "text/html" });
    fs.createReadStream("./index.html").pipe(res);
  } else if (req.url === "/favicon.ico") {
    res.writeHead(200, { "Content-Type": "image/x-icon" });
    fs.createReadStream("../favicon.ico").pipe(res);
  } else if (!req.url.includes("..") && fs.existsSync(distDir + req.url)) {
    res.writeHead(200, { "Content-Type": "text/javascript" });
    fs.createReadStream(distDir + req.url).pipe(res);
  } else {
    res.writeHead(404);
    res.end();
  }
});
server.listen(3000, "127.0.0.1");
console.log("Listening on http://localhost:3000");