Updates
This commit is contained in:
@@ -14,40 +14,16 @@ declare global {
|
||||
var NODE_ENVIRONMENT: any;
|
||||
}
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Initialization
|
||||
* ==============================================================================
|
||||
*/
|
||||
/** ********************* Create HTTP Server */
|
||||
const server = http.createServer();
|
||||
|
||||
/** ********************* Load environment variables */
|
||||
const key = process.env.DSQL_GITHUB_SECRET;
|
||||
|
||||
/** ********************* Set environment */
|
||||
let environment = process.env.NODE_ENVIRONMENT;
|
||||
|
||||
/** ********************* Set global variables */
|
||||
global.NODE_ENVIRONMENT = environment;
|
||||
|
||||
/** ********************* Set PORT */
|
||||
const PORT = process.env.DSQL_PORT;
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
const workingDirectory = path.resolve(__dirname, "../");
|
||||
|
||||
console.log(workingDirectory);
|
||||
@@ -62,32 +38,19 @@ child.on("exit", () => {
|
||||
console.log("Child Process Exited");
|
||||
});
|
||||
|
||||
/**
|
||||
* Handle Server Requests
|
||||
* ==============================================================================
|
||||
*/
|
||||
server.on("request", (req, res) => {
|
||||
/** ********************* Handle response Headers */
|
||||
if (!req.method?.match(/post/i)) {
|
||||
return res.writeHead(401, "Unauthorized").end();
|
||||
}
|
||||
|
||||
/** ********************* Initialize data */
|
||||
let data = "";
|
||||
|
||||
try {
|
||||
/** ********************* Handle Request Methods */
|
||||
/** # Handle POST Requests
|
||||
* =================================================
|
||||
*/
|
||||
req.on("data", (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
|
||||
req.on("end", () => {
|
||||
console.log("Request Recieved");
|
||||
|
||||
@@ -116,8 +79,8 @@ server.on("request", (req, res) => {
|
||||
if (environment?.match(/prod/i)) {
|
||||
spawnSync("git", ["checkout", "."], options);
|
||||
spawnSync("git", ["pull"], options);
|
||||
spawnSync("npm", ["install"], options);
|
||||
spawnSync("npm", ["run", "build"], options);
|
||||
spawnSync("bun", ["install"], options);
|
||||
spawnSync("bun", ["run", "build"], options);
|
||||
|
||||
child.kill();
|
||||
|
||||
@@ -128,7 +91,7 @@ server.on("request", (req, res) => {
|
||||
});
|
||||
} else {
|
||||
spawnSync("git", ["status"], options);
|
||||
spawnSync("npm", ["list", "next"], options);
|
||||
spawnSync("bun", ["list", "next"], options);
|
||||
|
||||
console.log("Not in production, Continuing ...");
|
||||
}
|
||||
@@ -140,10 +103,6 @@ server.on("request", (req, res) => {
|
||||
res.end("Failed");
|
||||
}
|
||||
});
|
||||
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.end(
|
||||
@@ -154,19 +113,6 @@ server.on("request", (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Fire up server
|
||||
* ==============================================================================
|
||||
*/
|
||||
// const numCpus = os.cpus().length;
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Listening on PORT ${PORT} => env: ${environment}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user