Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

View file

@ -0,0 +1,15 @@
language: node_js
node_js:
- '0.12'
- '4.0'
- 'stable'
script: "npm run test-travis"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
deploy:
provider: npm
email: thedillonb@gmail.com
api_key:
secure: IwwwZ4AFXheXI1N2XGJwfQXTZMNsVbhpyzcNyWHI9cihoatuwtIC1K7S2jTGXfm/IWJ6Fn7IgcyJ/uVXudUnHK0kqC5j0uss07gs/EXeqmJfi2vPKFWq3ajCrBz4HwIgcjjcNfJpWjwZzPb+yXAd2iC3QixmwtlhMh0T9zneOy0m5p/bZQxvCrCkb2XaBZ4t6tmjCt3b1HdU6wTxVqfa8s7hw2XyDFinFapJM2JVmErL3LCj46i65LzFNI7bEqW/say6U45/jAT2dFBISED4fbT7+o7d2Hyrop9DjMyNJMLEWDbEkBF73Juvn9y59H9ORDT2FJ1t8Owgs+mHHoNTAGhnjCdQqM0ZDlSXnUUsA3F7RB/+SXUNsKhRk/2oUwj6eItq9cCdosHeI//nJanGqxbfILxrHbIyqV5S8H+BxEV7MPQzJ5g4N2yr3sudsz/7CwxGi/eaa7eRjwdVvFA7+K/cSa2cIqCPckk/CyQaT9DLJBcDzLBAyuwyrwajBPAZU4OAlpH2QI0OSZchMYiixA4SvTQSd3LqVZkFbzk6TSkzn10zMhk7Lq+9cXMM/AJyvg3cRyjppWHFMRluQdfe5ANUGiLSeVs7FMl5/pJZ/siB36YTratTCZN27zaPrMgNWYBiopPhhrR1/F5JrjCj6ipnx7vBvvLZohXjaZMSHMo=
on:
tags: true
repo: thedillonb/http-shutdown

21
Frontend-Learner/node_modules/http-shutdown/LICENSE generated vendored Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Dillon Buchanan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

12
Frontend-Learner/node_modules/http-shutdown/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,12 @@
// Missing type definitions
import { Server } from 'net';
export = wrapShutdown;
interface WithShutdown extends Server {
shutdown(cb: (err?: Error) => any): void;
forceShutdown(cb: (err?: Error) => any): void;
}
declare function wrapShutdown<S extends Server>(s: S): S & WithShutdown;

85
Frontend-Learner/node_modules/http-shutdown/index.js generated vendored Normal file
View file

@ -0,0 +1,85 @@
'use strict';
var http = require('http');
var https = require('https');
/**
* Expose `addShutdown`.
*/
exports = module.exports = addShutdown;
/**
* Adds shutdown functionaility to the `http.Server` object
* @param {http.Server} server The server to add shutdown functionaility to
*/
function addShutdown(server) {
var connections = {};
var isShuttingDown = false;
var connectionCounter = 0;
function destroy(socket, force) {
if (force || (socket._isIdle && isShuttingDown)) {
socket.destroy();
delete connections[socket._connectionId];
}
};
function onConnection(socket) {
var id = connectionCounter++;
socket._isIdle = true;
socket._connectionId = id;
connections[id] = socket;
socket.on('close', function() {
delete connections[id];
});
};
server.on('request', function(req, res) {
req.socket._isIdle = false;
res.on('finish', function() {
req.socket._isIdle = true;
destroy(req.socket);
});
});
server.on('connection', onConnection);
server.on('secureConnection', onConnection);
function shutdown(force, cb) {
isShuttingDown = true;
server.close(function(err) {
if (cb) {
process.nextTick(function() { cb(err); });
}
});
Object.keys(connections).forEach(function(key) {
destroy(connections[key], force);
});
};
server.shutdown = function(cb) {
shutdown(false, cb);
};
server.forceShutdown = function(cb) {
shutdown(true, cb);
};
return server;
};
/**
* Extends the {http.Server} object with shutdown functionaility.
* @return {http.Server} The decorated server object
*/
exports.extend = function() {
http.Server.prototype.withShutdown = function() {
return addShutdown(this);
};
https.Server.prototype.withShutdown = function() {
return addShutdown(this);
};
};

View file

@ -0,0 +1,32 @@
{
"name": "http-shutdown",
"version": "1.2.2",
"description": "Gracefully shutdown a running HTTP server.",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "mocha",
"test-travis": "node --harmony node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --reporter dot"
},
"keywords": [
"http",
"https",
"graceful",
"force",
"shutdown"
],
"author": "Dillon Buchanan",
"repository": "thedillonb/http-shutdown",
"license": "MIT",
"devDependencies": {
"@types/node": "^12.12.6",
"chai": "^3.4.1",
"istanbul": "^0.4.1",
"mocha": "^2.3.4",
"request": "^2.67.0"
},
"engines": {
"iojs": ">= 1.0.0",
"node": ">= 0.12.0"
}
}

74
Frontend-Learner/node_modules/http-shutdown/readme.md generated vendored Normal file
View file

@ -0,0 +1,74 @@
# Http-Shutdown [![NPM version][npm-image]][npm-url] [![Build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url]
Shutdown a Nodejs HTTP server gracefully by doing the following:
1. Close the listening socket to prevent new connections
2. Close all idle keep-alive sockets to prevent new requests during shutdown
3. Wait for all in-flight requests to finish before closing their sockets.
4. Profit!
Other solutions might just use `server.close` which only terminates the listening socket and waits for other sockets to close - which is incomplete since keep-alive sockets can still make requests. Or, they may use `ref()/unref()` to simply cause Nodejs to terminate if the sockets are idle - which doesn't help if you have other things to shutdown after the server shutsdown.
`http-shutdown` is a complete solution. It uses idle indicators combined with an active socket list to safely, and gracefully, close all sockets. It does not use `ref()/unref()` but, instead, actively closes connections as they finish meaning that socket 'close' events still work correctly since the sockets are actually closing - you're not just `unref`ing and forgetting about them.
## Installation
```bash
$ npm install http-shutdown
```
## Usage
There are currently two ways to use this library. The first is explicit wrapping of the `Server` object:
```javascript
// Create the http server
var server = require('http').createServer(function(req, res) {
res.end('Good job!');
});
// Wrap the server object with additional functionality.
// This should be done immediately after server construction, or before you start listening.
// Additional functionailiy needs to be added for http server events to properly shutdown.
server = require('http-shutdown')(server);
// Listen on a port and start taking requests.
server.listen(3000);
// Sometime later... shutdown the server.
server.shutdown(function(err) {
if (err) {
return console.log('shutdown failed', err.message);
}
console.log('Everything is cleanly shutdown.');
});
```
The second is implicitly adding prototype functionality to the `Server` object:
```javascript
// .extend adds a .withShutdown prototype method to the Server object
require('http-shutdown').extend();
var server = require('http').createServer(function(req, res) {
res.end('God job!');
}).withShutdown(); // <-- Easy to chain. Returns the Server object
// Sometime later, shutdown the server.
server.shutdown(function(err) {
if (err) {
return console.log('shutdown failed', err.message);
}
console.log('Everything is cleanly shutdown.');
});
```
## Test
```bash
$ npm test
```
[npm-image]: https://img.shields.io/npm/v/http-shutdown.svg?style=flat-square
[npm-url]: https://npmjs.org/package/http-shutdown
[travis-image]: https://img.shields.io/travis/thedillonb/http-shutdown.svg?style=flat-square
[travis-url]: https://travis-ci.org/thedillonb/http-shutdown
[coveralls-image]: https://img.shields.io/coveralls/thedillonb/http-shutdown.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/thedillonb/http-shutdown

55
Frontend-Learner/node_modules/http-shutdown/test.js generated vendored Normal file
View file

@ -0,0 +1,55 @@
var http = require('http');
var httpShutdown = require('./index').extend();
var should = require('chai').should();
var request = require('request');
describe('http-shutdown', function(done) {
it('Should shutdown with no traffic', function(done) {
var server = http.createServer(function(req, res) {
done.fail();
}).withShutdown();
server.listen(16789, function() {
server.shutdown(function(err) {
should.not.exist(err);
done();
})
})
});
it('Should shutdown with outstanding traffic', function(done) {
var server = http.createServer(function(req, res) {
setTimeout(function() {
res.writeHead(200);
res.end('All done');
}, 500);
}).withShutdown();
server.listen(16789, function(err) {
request.get('http://localhost:16789/', function(err, response) {
should.not.exist(err);
response.statusCode.should.equal(200);
done();
});
setTimeout(server.shutdown, 100);
});
});
it('Should force shutdown without waiting for outstanding traffic', function(done) {
var server = http.createServer(function(req, res) {
setTimeout(function() {
done.fail();
}, 500);
}).withShutdown();
server.listen(16789, function(err) {
request.get('http://localhost:16789/', function(err, response) {
should.exist(err);
done();
});
setTimeout(server.forceShutdown, 100);
});
});
});