Skip to content

Commit

Permalink
server
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaki-1052 committed Jun 5, 2024
1 parent d217e0b commit e26d5c0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ HOST_CLIENT=localhost
# The Google API Key is only required if using Gemini.
# The Gemini models will simply fail to respond if left blank.
# The same applies for the Mistral and Claude APIs.

RESTART=TRUE
3 changes: 2 additions & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"verbose": true,
"env": {
"NODE_ENV": "development"
}
},
"signal": "SIGTERM"
}
2 changes: 1 addition & 1 deletion public/instructions.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
testing script...say "cheese" and nothing else!
testing script...say "success" and nothing else!
4 changes: 4 additions & 0 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,10 @@ function saveEnvChanges() {


document.addEventListener('DOMContentLoaded', function () {

console.log('DOM fully loaded and parsed');


document.getElementById('setupForm').addEventListener('submit', function (event) {
event.preventDefault();

Expand Down
17 changes: 17 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,8 @@ if (prompt === "Bye!") {

// Delay before shutting down the server to allow file download
setTimeout(() => {
console.log("Sending SIGTERM to self...");
process.kill(process.pid, 'SIGTERM'); // Send SIGTERM to self
server.close(() => {
console.log("Server successfully shut down.");
});
Expand Down Expand Up @@ -1031,6 +1033,8 @@ if (user_message === "Bye!") {

// Delay before shutting down the server to allow file download
setTimeout(() => {
console.log("Sending SIGTERM to self...");
process.kill(process.pid, 'SIGTERM'); // Send SIGTERM to self
server.close(() => {
console.log("Server successfully shut down.");
});
Expand Down Expand Up @@ -1362,6 +1366,8 @@ app.get('/export-chat-html', async (req, res) => {
isShuttingDown = true; // Set the shutdown flag
// Delay before shutting down the server to allow file download
setTimeout(() => {
console.log("Sending SIGTERM to self...");
process.kill(process.pid, 'SIGTERM'); // Send SIGTERM to self
server.close(() => {
console.log("Server successfully shut down.");
});
Expand Down Expand Up @@ -1421,6 +1427,8 @@ app.post('/shutdown-server', (req, res) => {
res.send('Server shutdown initiated');

setTimeout(() => {
console.log("Sending SIGTERM to self...");
process.kill(process.pid, 'SIGTERM'); // Send SIGTERM to self
server.close(() => {
console.log('Server successfully shut down.');
process.exit(0);
Expand Down Expand Up @@ -1478,4 +1486,13 @@ const HOST = isVercelEnvironment ? '0.0.0.0' : process.env.HOST_SERVER || 'local

const server = app.listen(PORT, HOST, () => {
console.log(`Server running at http://${HOST}:${PORT}`);
});

// Gracefully handle shutdown
process.on('SIGTERM', () => {
console.log('Received SIGTERM, shutting down gracefully...');
server.close(() => {
console.log('Server successfully shut down.');
process.exit(0);
});
});

0 comments on commit e26d5c0

Please sign in to comment.