From 44783dd74e92f2edc554795dce43d0fbe99166b3 Mon Sep 17 00:00:00 2001 From: xsahxl Date: Tue, 29 Mar 2022 14:36:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20server.timeout=20a?= =?UTF-8?q?nd=20keepAliveTimeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/code/index.js | 9 ++++++--- src/index.js | 23 ++++++++--------------- src/template.js | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 src/template.js diff --git a/src/code/index.js b/src/code/index.js index e4ec425..d2fd522 100644 --- a/src/code/index.js +++ b/src/code/index.js @@ -1,12 +1,15 @@ const express = require("express"); const path = require("path"); const app = express(); -const port = 9000; +const PORT = 9000; +const HOST = "0.0.0.0"; app.use(express.static(path.join(__dirname, "public"))); app.get("/*", function (req, res) { - res.sendFile(path.join(__dirname, "public", "index.html")); + res.sendFile(path.join(__dirname, "public", "$index")); }); -app.listen(port); +const server = app.listen(PORT, HOST); +server.timeout = 0; +server.keepAliveTimeout = 0; diff --git a/src/index.js b/src/index.js index a48d8b6..f58239a 100644 --- a/src/index.js +++ b/src/index.js @@ -21,21 +21,14 @@ module.exports = async function index(inputs, args) { fse.ensureDirSync(publicPath); fse.copySync(newCodeUri, publicPath); const index = lodash.get(args, "index", "index.html"); - const str = ` - const express = require("express"); - const path = require("path"); - const app = express(); - const port = 9000; - - app.use(express.static(path.join(__dirname, "public"))); - - app.get("/*", function (req, res) { - res.sendFile(path.join(__dirname, "public", "${index}")); - }); - - app.listen(port); - `; - fse.writeFileSync(path.join(__dirname, "./code/index.js"), str); + const indexData = fse.readFileSync( + path.join(__dirname, "template.js"), + "utf-8" + ); + fse.writeFileSync( + path.join(__dirname, "./code/index.js"), + lodash.replace(indexData, "$index", index) + ); return lodash.merge(inputs, { props: { function: { diff --git a/src/template.js b/src/template.js new file mode 100644 index 0000000..d2fd522 --- /dev/null +++ b/src/template.js @@ -0,0 +1,15 @@ +const express = require("express"); +const path = require("path"); +const app = express(); +const PORT = 9000; +const HOST = "0.0.0.0"; + +app.use(express.static(path.join(__dirname, "public"))); + +app.get("/*", function (req, res) { + res.sendFile(path.join(__dirname, "public", "$index")); +}); + +const server = app.listen(PORT, HOST); +server.timeout = 0; +server.keepAliveTimeout = 0;