Skip to content

Instantly share code, notes, and snippets.

const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const bodyParser = require('body-parser');
const md5 = require('md5');
const app = express();
app.use(bodyParser.json());
const dbUrl = "mongodb://localhost:27017"
events {
worker_connections 1024;
}
http {
keepalive_timeout 65;
server {
listen 80;
location / {
events {
worker_connections 1024;
}
http {
keepalive_timeout 65;
server {
listen 80;
location / {
const http = require('http');
const keepAliveAgent = new http.Agent({
keepAlive: true,
// 多久發一次 tcp keep-alive 檢查
keepAliveMsecs: 4000
});
const options = {
hostname: 'localhost',
port: 3000,
path: '/',
var net = require('net');
var opts = {
host: 'localhost',
port: 3000
}
var socket = net.connect(opts, function () {
socket.end('GET / HTTP/1.0\r\n' +
'Host: localhost\r\n' +
#!/usr/bin/env node
import cdk = require('@aws-cdk/cdk');
import { AwsCdkStack } from '../lib/aws-cdk-stack';
const app = new cdk.App();
new AwsCdkStack(app, 'AwsCdkStack', {
env: {
region: 'us-west-1'
}
});
@sj82516
sj82516 / aws-cdk-stack.ts
Last active January 27, 2019 02:40
aws-cdk-test
import path = require('path');
import cdk = require('@aws-cdk/cdk');
import lambda = require('@aws-cdk/aws-lambda');
import event = require('@aws-cdk/aws-events');
export class AwsCdkStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
var express = require('express')
require('express-async-errors')
var app = express()
var pE = require("./promisifyError")
var rt = express.Router();
app.get('/', async function (req, res, next) {
await pE();
})
const Koa = require('koa');
const app = new Koa();
app.use(async (ctx, next) => {
try {
await next();
}catch(error){
console.error(error);
ctx.body = "ServerError";
}
@sj82516
sj82516 / tPromise.js
Last active August 21, 2018 04:54
implement promise
class tPromise {
constructor(fn){
this.status = "pedding"
this._queue = []
this._catch = ()=>{ console.error("unhandle tPromise error") }
fn.call(this, this.resolve.bind(this), this.reject.bind(this))
}
resolve(data){
this.status = "resolved";