Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict'
const Lab = require('@hapi/lab')
const Code = require('@hapi/code')
const Hapi = require('@hapi/hapi')
const server = new Hapi.Server()
const { experiment, test, before } = (exports.lab = Lab.script())
experiment('hapi-dev-error register plugin', () => {
before(async () => {
// fake production env
process.env.NODE_ENV = 'production'
await server.register({
plugin: require('../lib/index'),
options: {
showErrors: process.env.NODE_ENV !== 'production'
}
})
})
const Hapi = require('@hapi/hapi');
const secret = 'NeverShareYourSecret';
// for debug options see: http://hapijs.com/tutorials/logging
let debug;
// debug = { debug: { 'request': ['error', 'uncaught'] } };
debug = { debug: false };
const server = new Hapi.Server(debug);
const sendToken = function(req, reply) {
return req.auth.token || null;
};
const privado = function(req, reply) {
return req.auth.credentials;
};
// defining our own validate function lets us do something
// useful/custom with the decodedToken before reply(ing)
const customVerify = function (decoded, request) {
if(decoded.error) {
throw new Error('customVerify fails!');
}
else if (decoded.custom_error) {
internals.start = async function () {
const server = Hapi.server({ host: 'localhost', port: 8000 });
await server.register(Bell);
// You'll need to go to https://developers.facebook.com/ and set up a
// Website application to get started
// Once you create your app, fill out Settings and set the App Domains
// Under Settings >> Advanced, set the Valid OAuth redirect URIs to include http:///bell/door
// and enable Client OAuth Login
server.auth.strategy('facebook', 'bell', {
provider: 'facebook',
password: 'cookie_encryption_password_secure',
isSecure: false,
clientId: '',
clientSecret: '',
location: server.info.uri
});
const createServer = async () => {
// Create a server with a host and port
const server = Hapi.server({
port: process.env.PORT || 3000
});
// Register vendors plugins
await server.register([
require('blipp'),
require('@hapi/inert'),
require('@hapi/vision'),
{
plugin: require('hapi-swagger'),
options: {
info: {
title: 'Test API Documentation',
version: Package.version,
},
}
const Hapi = require('@hapi/hapi')
const Inert = require('@hapi/inert')
const mkdirp = require('mkdirp')
const path = require('path')
const youtube = require('./handlers/youtube')
const server = new Hapi.Server({
port: process.env.PORT || 3000,
routes: {
files: {
relativeTo: path.join(__dirname, '../../public')
}
}
})
const provision = async () => {
await server.register(Inert)
// TODO add notifications to app
// TODO remove duplicate downloads from ui
server.route({
method: 'GET',
path: '/{path*}',
;(async () => {
/* setup network service */
let server = new HAPI.Server({
address: "0.0.0.0",
port: 12345
})
/* establish the HAPI route for GraphiQL UI */
await server.register({
plugin: HAPIGraphiQL,
options: {
graphiqlURL: "/api",
graphqlFetchURL: "/api",
graphqlFetchOpts: `{
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
it('authenticates with mock', async (flags) => {
const mock = await Mock.v2(flags);
const server = Hapi.server({ host: 'localhost', port: 80 });
await server.register(Bell);
const custom = Bell.providers.bitbucket();
Hoek.merge(custom, mock.provider);
Mock.override('https://api.bitbucket.org/2.0/user', {
repositories: [{}],
uuid: '1E9C5160-E436-11E5-9897-4FCB70D5A8C7',
username: 'steve',
display_name: 'steve'
});
server.auth.strategy('custom', 'bell', {
password: 'cookie_encryption_password_secure',
isSecure: false,
clientId: 'bitbucket',
it('binds onResponse to plugin bind', async () => {
const upstream = Hapi.server();
await upstream.start();
const plugin = {
register: function (server, options) {
const onResponseWithError = function (err, res, request, h, settings, ttl) {
expect(err).to.be.null();
return h.response(h.context.c);
};
const handler = {
proxy: {
host: 'localhost',
port: upstream.info.port,
onResponse: onResponseWithError
it('allows passing in an agent through to Wreck', { parallel: false }, async () => {
const server = Hapi.server();
await server.register(H2o2);
const agent = { name: 'myagent' };
const httpClient = {
request(method, uri, options, callback) {
expect(options.agent).to.equal(agent);
return { statusCode: 200 };
}
};
server.route({ method: 'GET', path: '/agenttest', handler: { proxy: { uri: 'http://localhost', httpClient, agent } } });
await server.inject({ method: 'GET', url: '/agenttest', headers: {} }, (res) => { });
});
test('should get DB instance on request', async () => {
const server = new Hapi.Server();
await server.register([
{
plugin: require('../lib/'),
options: [
{
name: 'test',
models: [Path.join(__dirname, '/models/**/*.js')],
sync: true,
sequelize: new Sequelize('test', null, null, {
logging: false,
dialect: 'sqlite',
storage: Path.join(__dirname, 'db.sqlite'),
}),
},
],