Skip to content

Commit

Permalink
feat: 🎸 add server.timeout and keepAliveTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
xsahxl committed Mar 29, 2022
1 parent a25c973 commit 44783dd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
9 changes: 6 additions & 3 deletions src/code/index.js
Original file line number Diff line number Diff line change
@@ -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;
23 changes: 8 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
15 changes: 15 additions & 0 deletions src/template.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 44783dd

Please sign in to comment.