本文整理汇总了TypeScript中hapi.Server.connection方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Server.connection方法的具体用法?TypeScript Server.connection怎么用?TypeScript Server.connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hapi.Server
的用法示例。
在下文中一共展示了Server.connection方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createApp
function createApp(createOptions: HapiPluginOptions) {
const server = new hapi.Server();
server.connection({
host: 'localhost',
port: 8000,
});
server.register({
register: apolloHapi,
options: {
apolloOptions: createOptions ? createOptions.apolloOptions : { schema: Schema },
path: '/graphql',
},
});
server.register({
register: graphiqlHapi,
options: {
path: '/graphiql',
graphiqlOptions: {
endpointURL: '/graphql',
},
},
});
return server.listener;
}
示例2: createApp
function createApp(options: CreateAppOptions) {
const server = new hapi.Server();
server.connection({
host: 'localhost',
port: 8000,
});
server.register({
register: graphqlHapi,
options: {
graphqlOptions: (options && options.graphqlOptions) || { schema: Schema },
path: '/graphql',
},
});
server.register({
register: graphiqlHapi,
options: {
path: '/graphiql',
graphiqlOptions: (options && options.graphiqlOptions) || { endpointURL: '/graphql' },
},
});
return server.listener;
}
示例3: init
public static init(): Hapi.Server {
const server = new Hapi.Server();
server.connection({
port: 10000,
router: {
isCaseSensitive: false,
stripTrailingSlash: true
},
routes: {
timeout: {
server: 10000,
socket: false
},
cors: {
credentials: true,
origin: ['*'],
headers: ['Accept', 'Authorization',
'Content-Type', 'If-None-Match',
'Access-Control-Allow-Origin',
'Accept-Language']
},
files: {
relativeTo: Path.join(__dirname, '../')
}
}
});
server.ext('onPreResponse', corsHeaders);
server.register(Inert, () => {});
Api.init(server);
return server;
}
示例4: start
async function start() {
const server = new Hapi.Server();
const env = process.env.NODE_ENV || 'development';
process.env.NODE_ENV = env; //So the plugins load right
const configFilePath = path.join(__dirname, "config", env + ".json");
const userConfigFilePath = path.join(__dirname, "config", env + ".user.json");
nconf
.file("user_overrides", userConfigFilePath)
.file("defaults", configFilePath);
server.connection({
host: nconf.get('hapi:host'),
port: nconf.get('hapi:port')
});
const appLogger = new AppLogger();
server.app.logger = await appLogger.initialize(nconf);
await Plugin.registerAll(server, nconf);
await Api.loadRoutes(server);
await server.start();
if (server.info !== null) {
server.app.logger.info(`Server running at ${server.info.uri}`);
}
}
示例5: initialize
protected initialize() {
this.engine = new Hapi();
this.engine.connection({
host: 'localhost',
port: 3000
});
return this;
}
示例6: startServer
export default function startServer(done) {
const server = new Hapi.Server({
connections: {
routes: {
files: {
relativeTo: Path.join(__dirname, '..')
}
}
}
});
server.connection({ port: 3000, host: 'localhost' });
server.register(Inert, (err) => {
if (err) {
throw err;
}
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply.file('index.html');
}
});
server.route({
method: 'GET',
path: '/scripts/{param*}',
handler: {
directory: {
path: 'scripts'
}
}
});
server.route({
method: 'GET',
path: '/styles/{param*}',
handler: {
directory: {
path: 'styles'
}
}
});
server.route({
method: 'GET',
path: '/api/system/current',
handler: function (request, reply) {
reply.file('c3.json');
}
});
server.start((err) => {
if (err) {
throw err;
}
console.log(`Server running at: ${server.info.uri}`);
});
});
done();
}
示例7: function
module.exports = function(ROOT, serverOptions) {
var {hapiEngine} = require('angular2-hapi-engine');
var app = new Hapi.Server();
app.connection(serverOptions);
app.register([Vision, Inert], (err) => {
if (err) {
throw err;
}
// rendering engine
app.views({
defaultExtension: 'ng2.html',
engines: {
'ng2.html': {
module: new hapiEngine(),
compileMode: 'async'
}
},
relativeTo: __dirname,
path: path.join(ROOT, 'examples')
});
});
var routes = require('./routes');
app.route(routes(ROOT));
var api = require('./api');
app.route(api(ROOT));
// TODO: is this script being used?
// var graphApi = require('./graph_api');
// app.use('/graph_api', api(ROOT));
// TODO: what route is this?
// app.use(serveStatic(`${ROOT}/dist`));
// TODO: figure out how to use morgan with Hapi
// app.use(morgan('dev'));
return app;
};
示例8:
SwaggerHapi.create(config, (err, swaggerHapi) => {
if (err) { throw err; }
const port = process.env.PORT || 10010;
app.connection({ port });
// app.address = function() {
// return { port };
// };
if (swaggerHapi.config.swagger !== undefined) {
const appRootFromMw = swaggerHapi.config.swagger.appRoot;
}
app.register(swaggerHapi.plugin, err => {
if (err) { return console.error("Failed to load plugin:", err); }
// stat app etc..
});
});
示例9: resolve
return new Promise<Hapi.Server>(resolve => {
const port = process.env.PORT || configs.port;
const server = new Hapi.Server();
server.connection({
port: port,
routes: {
cors: true
}
});
if (configs.routePrefix) {
server.realm.modifiers.route.prefix = configs.routePrefix;
}
// Setup Hapi Plugins
const plugins: Array<string> = configs.plugins;
const pluginOptions = {
database: database,
serverConfigs: configs
};
let pluginPromises = [];
plugins.forEach((pluginName: string) => {
var plugin: IPlugin = (require("./plugins/" + pluginName)).default();
console.log(`Register Plugin ${plugin.info().name} v${plugin.info().version}`);
pluginPromises.push(plugin.register(server, pluginOptions));
});
Promise.all(pluginPromises).then(() => {
console.log('All plugins registered successfully.');
console.log('Register Routes');
Tasks.init(server, configs, database);
Users.init(server, configs, database);
console.log('Routes registered sucessfully.');
resolve(server);
});
});
示例10:
SwaggerNodeRunner.create(config, (err, runner) => {
if (err) { throw err; }
var port = process.env.PORT || 10010;
hapiapp.connection({ port });
// hapiapp.address = function() {
// return { port };
// };
const hapiMiddleware = runner.hapiMiddleware();
if (hapiMiddleware.config.swagger !== undefined) {
const appRootFromMw = hapiMiddleware.config.swagger.appRoot;
}
const pluginAttributes = hapiMiddleware.plugin.register.attributes.name + hapiMiddleware.plugin.register.attributes.version;
hapiapp.register(hapiMiddleware.plugin, err => {
if (err) { return console.error("Failed to load plugin:", err); }
// stat app etc..
});
});