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) {
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"
},
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'),
}),
},
],
it('should expose access to the registered jobs', async () => {
const server = new Hapi.Server();
await server.register({
plugin: HapiCron,
options: {
jobs: [{
name: 'testcron',
time: '*/10 * * * * *',
timezone: 'Europe/London',
request: {
method: 'GET',
url: '/test-url'
}
}]
}
});
internals.main = async function () {
const server = Hapi.Server({ port: 3000 });
await server.register(Vision);
server.views({
engines: {
html: {
compile: function (template) {
Mustache.parse(template);
return function (context) {
return Mustache.render(template, context);
};
}
}
public static async start(): Promise {
try {
DotEnv.config({
path: `${process.cwd()}/.env`,
});
Server._instance = new Hapi.Server({
port: process.env.PORT,
});
await Plugin.registerAll(Server._instance);
await Router.loadRoutes(Server._instance);
await Server._instance.start();
Logger.info(
`Server - Up and running at http://${process.env.HOST}:${process.env.PORT}`
);
Logger.info(
`Server - Visit http://${process.env.HOST}:${process.env.PORT}/api/users for REST API`
);
Logger.info(
`Server - Visit http://${process.env.HOST}:${process.env.PORT}/documentation for Swagger docs`
(async () => {
try {
const server = Hapi.Server({
host: 'localhost',
port: process.argv[2] || 8080
});
await server.register(H2o2);
server.route({
method: 'GET',
path: '/proxy',
handler: {
proxy: {
host: '127.0.0.1',
port: 65535
}
}
});
(async () => {
try {
const serverPort = process.argv[2] || 8080;
const server = Hapi.Server({
host: 'localhost',
port: serverPort
});
await server.register(Vision);
server.views({
engines: {
html: Handlebars
},
path: Path.join(__dirname, 'templates')
});
server.route({
path: '/',
method: 'GET',