This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
events { | |
worker_connections 1024; | |
} | |
http { | |
keepalive_timeout 65; | |
server { | |
listen 80; | |
location / { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
events { | |
worker_connections 1024; | |
} | |
http { | |
keepalive_timeout 65; | |
server { | |
listen 80; | |
location / { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const keepAliveAgent = new http.Agent({ | |
keepAlive: true, | |
// 多久發一次 tcp keep-alive 檢查 | |
keepAliveMsecs: 4000 | |
}); | |
const options = { | |
hostname: 'localhost', | |
port: 3000, | |
path: '/', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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' | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Koa = require('koa'); | |
const app = new Koa(); | |
app.use(async (ctx, next) => { | |
try { | |
await next(); | |
}catch(error){ | |
console.error(error); | |
ctx.body = "ServerError"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |