当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript http.createServer函数代码示例

本文整理汇总了TypeScript中http.createServer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createServer函数的具体用法?TypeScript createServer怎么用?TypeScript createServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createServer函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

 constructor() {
     this.application = express();
     this.server = http.createServer(this.application);
 }
开发者ID:tierratelematics,项目名称:prettygoat,代码行数:4,代码来源:ServerProvider.ts

示例2: Router

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`)
})
开发者ID:YimYijet,项目名称:WebTest,代码行数:30,代码来源:app.ts

示例3:

#!/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}`); 
开发者ID:erik-jenkins,项目名称:Notarama,代码行数:11,代码来源:server.ts

示例4: require

/// <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}`);
    });
开发者ID:miguel76,项目名称:MusicDB,代码行数:30,代码来源:server.ts

示例5: SocketIo

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));
});
开发者ID:TeamworkGuy2,项目名称:DefinitelyTyped,代码行数:31,代码来源:socketio-jwt-tests.ts

示例6: Express

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: "./" });
});
开发者ID:noodlecrate,项目名称:noodlecrate.github.io,代码行数:18,代码来源:index.ts

示例7: ReadyState

        [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) {
开发者ID:asrytis,项目名称:dice-game,代码行数:32,代码来源:index.ts

示例8: callback

                  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);
开发者ID:KostyaTretyak,项目名称:DefinitelyTyped,代码行数:30,代码来源:soap-tests.ts

示例9: Application

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}`));
开发者ID:yarrem,项目名称:facebookChatBotApi,代码行数:21,代码来源:main.ts

示例10: Subject

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$)
开发者ID:taavit,项目名称:typescript-rx-http-server,代码行数:30,代码来源:index.ts


注:本文中的http.createServer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。