constructor() {
     this.application = express();
     this.server = http.createServer(this.application);
 }
示例#2
0
文件: app.ts 项目: YimYijet/WebTest
const router = new Router()

function getData(): Promise<any> {
    return new Promise((resolve, reject) => {
        request.get('https://store.steampowered.com/stats/').end((err, res) => {
            if (err) {
                reject(err)
            }
            const $ = cheerio.load(res.text), temp: object[] = []
            $('#detailStats tbody tr').each((index, item) => {
                temp.push({
                    cur: $(item).find('td:first-child').text().trim(),
                    name: $(item).find('td:last-child').text().trim(),
                    peak: $(item).find('td:nth-child(2)').text().trim(),
                })
            })
            resolve(temp)
        })
    })
}

router.get('/', async (ctx: Koa.Context, next: () => void) => {
    ctx.body = await getData()
})

app.use(router.routes())

http.createServer(app.callback()).listen(3344, () => {
    console.log(`http server listening on port: 3344`)
})
示例#3
0
#!/usr/bin/env node

import * as http from 'http';
import * as app from '../app';

let server = http.createServer(app);
let port = process.env.port || '5000';

app.set('port', port);
server.listen(port);
console.log(`Server listening on port: ${port}`); 
示例#4
0
/// <reference path="../typings/main/ambient/mime/index.d.ts" />
/// <reference path="../typings/main/ambient/mongoose/index.d.ts" />
/// <reference path="../typings/main/ambient/morgan/index.d.ts" />
/// <reference path="../typings/main/ambient/node/index.d.ts" />
/// <reference path="../typings/main/ambient/serve-static/index.d.ts" />

'use strict';

if ('production' === process.env.NODE_ENV)
    require('newrelic');

var PORT = process.env.PORT || 3333;

import * as express from 'express';
import * as os from 'os';
import * as http from 'http';
import {RoutesConfig} from './config/routes.conf';
import {DBConfig} from './config/db.conf';
import {Routes} from './routes/index';

const app = express();

RoutesConfig.init(app, express);
Routes.init(app, express.Router());

http.createServer(app)
    .listen(PORT, () => {
      console.log(`up and running @: ${os.hostname()} on port: ${PORT}`);
      console.log(`enviroment: ${process.env.NODE_ENV}`);
    });
import * as fs from 'fs';
import * as http from 'http';
import * as SocketIo from 'socket.io';
import { authorize, JwtSecretFuncCallback } from 'socketio-jwt';

const app = http.createServer((req: any, rsp: any) => {
	fs.readFile(__dirname + '/index.html',
		(err: Error | null, data: any) => {
			if (err) {
				rsp.writeHead(500);
				return rsp.end('Error loading index.html');
			}

			rsp.writeHead(200);
			rsp.end(data);
		});
});

const io = SocketIo(app);

// This example test code is using the Node Http Server

io.on('connection', authorize({
	secret: 'Your Secret Here',
	decodedPropertyName: 'anyNameYouWant'
}));

io.on('authenticated', (socket: SocketIo.Socket) => {
	console.log('authenticated!!');
	console.log(JSON.stringify((socket as any).anyNameYouWant));
});
import * as Express from "express";
import * as http from "http";

let app = Express();

app.set("port", process.env.PORT || 2900);
app.use(Express.static("public"));
app.use("/node_modules", Express.static("node_modules"));


http.createServer(app).listen(app.get("port"), () => {
  console.log("Express server listening on port " + app.get("port"));
});

//in case can't find path it's probably SPA so...
app.use(function(req: any, res: any, next: any) {
  res.status(200).sendFile("/public/index.html", { root: "./" });
});
示例#7
0
        [GAME_STATE_READY]: new ReadyState(gameRoom),
        [GAME_STATE_IN_PROGRESS]: new InProgressState(gameRoom)
    })
});

const gameServer = new GameServer({ roomFactory });

//
// Providing the number of players online
//
const server = http.createServer(function(req, res) {
    
    if (req.url === `${config.httpPath}/player-count`) {
        res.writeHead(200, { 'Content-Type': 'application/json' });
        
        return res.end(JSON.stringify({
            playerCount: gameServer.playerCount
        }));
    }

    res.end();
});

//
// Websocket server
//
const wss = new WebSocketServer({
    server,
    path: config.wsPath
});

wss.on('connection', function(ws) {
                  callback({
                      name: args.name
                  });
              },
 
              // This is how to receive incoming headers 
              HeadersAwareFunction: function(args: any, cb: any, headers: any) {
                  return {
                      name: headers.Token
                  };
              },
 
              // You can also inspect the original `req` 
              reallyDeatailedFunction: function(args: any, cb: any, headers: any, req: any) {
                  console.log('SOAP `reallyDeatailedFunction` request from ' + req.connection.remoteAddress);
                  return {
                      name: headers.Token
                  };
              }
          }
      }
  };
 
var xml = fs.readFileSync('myservice.wsdl', 'utf8'),
    server = http.createServer(function(request,response) {
        response.end("404: Not Found: " + request.url);
    });
 
server.listen(8000);
soap.listen(server, '/wsdl', myService, xml);
示例#9
0
import { createServer } from 'http';
import * as nconf from 'nconf'
import { Application } from './app';
import { Socket } from 'net';
import { MessageTypes } from './sharedParts/enums/messageTypes';

nconf.argv().env();

let port: number = nconf.get('port');
let messageServicePort = nconf.get('mServicePort');
let messageServiceHost = nconf.get('mServiceHost');

let app = new Application(MessageTypes);
let client = new Socket();

client.connect(messageServicePort, messageServiceHost, function() {
    console.log(`CONNECTED TO: ${messageServicePort}:${messageServiceHost}`);
});
let server = createServer(app.start(client));

server.listen(port, () => console.info(`Facebook chat bot server is listenning on port: ${port}`));
示例#10
0
import * as http from 'http';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { NextObserver } from 'rxjs/Observer';

import 'rxjs/add/observable/merge';

import { RequestAction } from './RequestAction';
import { Emitable } from './Emitable';

import { aboutPage } from './pages/aboutPage';
import { welcomePage } from './pages/welcomePage';
import { notFoundPage } from './pages/notFoundPage';

const server: http.Server = http.createServer();

const requests$ = new Subject();

// Push data to RX
server.addListener(
    'request',
    (request, response) => requests$.next(new RequestAction(request, response))
);

// Combine services
const app = Observable.merge<RequestAction>(
        aboutPage(requests$),
        welcomePage(requests$),
        // If all previous routes failed we can return 404 response
        notFoundPage(requests$)