-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shirtiny
committed
Jun 25, 2021
1 parent
f6caf97
commit e70baea
Showing
3 changed files
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* @Author: Shirtiny | ||
* @Date: 2021-06-25 17:35:25 | ||
* @LastEditTime: 2021-06-25 21:18:09 | ||
* @Description: | ||
*/ | ||
"use strict"; | ||
|
||
const esbuild = require("esbuild"); | ||
const http = require("http"); | ||
const path = require("path"); | ||
const open = require("open"); | ||
const chalk = require("chalk"); | ||
|
||
esbuild | ||
.serve( | ||
{ | ||
servedir: path.resolve(__dirname, "../dist"), | ||
host: "localhost", | ||
}, | ||
{ | ||
entryPoints: [path.resolve(__dirname, "../src/main.ts")], | ||
outfile: path.resolve(__dirname, "../dist/main.dev.js"), | ||
platform: "browser", | ||
globalName: "bvplayer_core", | ||
bundle: true, | ||
sourcemap: "external", | ||
}, | ||
) | ||
.then((result) => { | ||
const { host, port } = result; | ||
|
||
const proxyServerPort = 2021; | ||
|
||
http | ||
.createServer((req, res) => { | ||
const options = { | ||
hostname: host, | ||
port: port, | ||
path: req.url, | ||
method: req.method, | ||
headers: req.headers, | ||
}; | ||
|
||
console.log( | ||
`${chalk.greenBright.bold( | ||
req.method.toUpperCase(), | ||
)} ${chalk.blueBright.underline.italic(`${req.url}`)} ${chalk.cyan( | ||
"->", | ||
)} ${chalk.yellowBright(res.statusCode)}`, | ||
); | ||
|
||
const proxyReq = http.request(options, (proxyRes) => { | ||
res.writeHead(proxyRes.statusCode, proxyRes.headers); | ||
proxyRes.pipe(res, { end: true }); | ||
}); | ||
|
||
req.pipe(proxyReq, { end: true }); | ||
}) | ||
.listen(proxyServerPort); | ||
|
||
open(`http://${host}:${proxyServerPort}`); | ||
|
||
console.log( | ||
`build server listen in ${host}:${port} ,proxy server listen in ${host}:${proxyServerPort}`, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.