本文整理汇总了TypeScript中gearworks.Server类的典型用法代码示例。如果您正苦于以下问题:TypeScript Server类的具体用法?TypeScript Server怎么用?TypeScript Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: registerRoutes
export function registerRoutes(server: Server)
{
server.route({
method: "GET",
path: Routes.GetShopify,
config: {
auth: {
strategies: [strategies.basicAuth, strategies.shopifyRequest],
}
},
handler: {
async: (request, reply) => connectShopify(server, request, reply),
}
});
server.route({
method: "GET",
path: Routes.GetShopifyActivate,
config: {
auth: {
strategies: [strategies.basicAuth, strategies.shopifyRequest],
}
},
handler: {
async: (request, reply) => activateShopifyPlan(server, request, reply),
}
})
}
示例2: startServer
async function startServer()
{
//Validate environment variables
Object.getOwnPropertyNames(config).forEach((prop, index, propNames) =>
{
// Ensure config prop isn't optional
if (config.OptionalProps.indexOf(prop) === -1 && typeof config[prop] === "undefined")
{
throw new Error(`Configuration property ${prop} cannot be null or empty. Check modules/config.ts to find the correct environment variable key for ${prop}.`);
}
})
//Configure the server's app state
server.app = {
appName: config.AppName,
isLive: config.isLive,
rootDir: path.resolve(__dirname),
};
await registerPlugins();
//Configure authentication. Must be done before configuring routes
configureAuth(server);
//Filter all responses to check if they have an error. If so, render the error page.
server.ext("onPreResponse", (request, reply) =>
{
const resp = request.response;
if (resp.header)
{
resp.header("X-STAGES-API-VERSION", "1.0.0");
}
return reply.continue();
});
//Register all app routes.
RoutesToRegister.forEach((register) => register(server));
return server.start((error) =>
{
if (error)
{
throw error;
}
console.log(`${server.app.isLive ? "Live" : "Development"} server running at ${server.info.uri}`);
})
}
示例3: registerRoutes
export default function registerRoutes(server: Server)
{
server.route({
path: "/users",
method: "POST",
config: {
auth: strategies.masterAuth,
validate:{
payload: joi.object().keys({
name: joi.string().label("Name"),
username: joi.string().email().label("Username"),
password: joi.string().min(6).label("Password"),
accountId: joi.string().label("Account Id"),
})
},
},
handler: {
async: (request, reply) => createUser(server, request, reply)
}
})
server.route({
path: "/users/{id}",
method: "GET",
config: {
auth: strategies.accountAuth,
validate: {
params: joi.string().required().label("User Id")
}
},
handler: {
async: (request, reply) => getUser(server, request, reply)
}
})
server.route({
path: "/users/{id}",
method: "PUT",
config: {
auth: strategies.accountAuth,
validate: {
params: joi.string().required().label("User Id")
}
},
handler: {
async: (request, reply) => updateUser(server, request, reply),
}
})
}
示例4: registerRoutes
export function registerRoutes(server: Server)
{
server.route({
method: "GET",
path: Routes.GetSetup,
config: {
auth: strategies.basicAuth,
},
handler: {
async: (request, reply) => getSetupForm(server, request, reply)
}
});
server.route({
method: "POST",
path: Routes.PostSetup,
config: {
auth: strategies.basicAuth,
},
handler: {
async: (request, reply) => setup(server, request, reply)
}
});
server.route({
method: "GET",
path: Routes.GetPlans,
config: {
auth: strategies.basicAuth,
},
handler: {
async: (request, reply) => getPlans(server, request, reply)
}
});
server.route({
method: "POST",
path: Routes.PostPlans,
config: {
auth: strategies.basicAuth,
},
handler: {
async: (request, reply) => selectPlan(server, request, reply)
}
})
}
示例5: registerRoutes
export function registerRoutes(server: Server)
{
server.route({
path: Routes.GetHome,
method: "GET",
handler: {
async: (request, reply) => getHomepage(server, request, reply)
}
})
}
示例6: registerRoutes
export function registerRoutes(server: Server)
{
server.route({
method: "POST",
path: Routes.GetAppUninstalled,
config: {
auth: strategies.shopifyWebhook
},
handler: {
async: (request, reply) => handleAppUninstalled(server, request, reply)
}
})
}
示例7: registerRoutes
export function registerRoutes(server: Server)
{
server.route({
method: "OPTIONS",
path: Routes.AppConfig,
config: {
auth: false,
plugins: {
crumb: false,
}
},
handler: {
async: (request, reply) => options(server, request, reply)
}
})
server.route({
method: "GET",
path: Routes.AppConfig,
config: {
auth: false,
plugins: {
crumb: false,
}
},
handler: {
async: (request, reply) => getAppConfig(server, request, reply)
}
});
server.route({
method: "PUT",
path: Routes.AppConfig,
handler: {
async: (request, reply) => updateAppConfig(server, request, reply)
},
})
}
示例8: registerRoutes
export function registerRoutes(server: Server)
{
server.route({
method: "GET",
path: Routes.GetTag,
config: {
auth: false,
plugins: {
crumb: false,
}
},
handler: {
async: (request, reply) => getTag(server, request, reply)
}
});
}
示例9: registerRoutes
export function registerRoutes(server: Server)
{
server.route({
path: "/account",
method: "GET",
handler: (request, reply) => reply.redirect(Routes.GetSettings),
})
server.route({
path: Routes.GetSettings,
method: "GET",
handler: {
async: (request, reply) => getSettings(server, request, reply),
}
})
server.route({
path: Routes.PostSettings,
method: "POST",
handler: {
async: (request, reply) => postSettings(server, request, reply)
}
})
server.route({
path: Routes.GetBilling,
method: "GET",
handler: {
async: (request, reply) => getBilling(server, request, reply),
}
})
server.route({
path: Routes.PostBilling,
method: "POST",
handler: {
async: (request, reply) => postBilling(server, request, reply),
}
})
server.route({
path: Routes.UpdatePlan,
method: "GET",
config: {
auth: {
strategies: [strategies.basicAuth, strategies.shopifyRequest],
}
},
handler: {
async: (request, reply) => updatePlan(server, request, reply)
}
})
}
示例10: registerPlugins
async function registerPlugins()
{
//Inert gives Hapi static file and directory handling via reply.file and reply.directory.
await server.register(require("inert"));
//Adds async support to Hapi route handlers.
await server.register(require("hapi-async-handler"));
//Yar is a cookie management plugin for Hapi.
await server.register({
register: require("yar"),
options: {
storeBlank: false,
cookieOptions: {
password: config.YarSalt,
isSecure: server.app.isLive,
ttl: 7 * 24 * 60 * 60 * 1000, // 7 days in milliseconds
ignoreErrors: true, //tells Hapi that it should not respond with a HTTP 400 error if the session cookie cannot decrypt
clearInvalid: true //tells Hapi that if a session cookie is invalid for any reason, to clear it from the browser.
}
}
})
await registerCaches(server);
}