-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (63 loc) · 1.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
const ImageStore = require('./app/utils/image-store');
const Hapi = require('@hapi/hapi');
const dotenv = require('dotenv');
const Joi = require("@hapi/joi");
const utils = require("./app/api/utils.js");
const credentials = {
cloud_name: process.env.name,
api_key: process.env.key,
api_secret: process.env.secret
};
const result = dotenv.config();
if (result.error) {
console.log(result.error.message);
process.exit(1);
}
const server = Hapi.server({
port: process.env.PORT || 4000,
routes: { cors: true },
});
require('./app/models/db');
async function init() {
await server.register(require('@hapi/inert'));
await server.register(require('@hapi/vision'));
await server.register(require('@hapi/cookie'));
await server.register(require('hapi-auth-jwt2'));
server.validator(require("@hapi/joi"));
ImageStore.configure(credentials);
server.auth.strategy('session', 'cookie', {
cookie: {
name: process.env.cookie_name,
password: process.env.cookie_password,
isSecure: false
},
redirectTo: '/'
});
server.auth.strategy("jwt", "jwt", {
key: "secretpasswordnotrevealedtoanyone",
validate: utils.validate,
verifyOptions: { algorithms: ["HS256"] },
});
server.auth.default('session');
server.views({
engines: {
hbs: require('handlebars')
},
relativeTo: __dirname,
path: './app/views',
layoutPath: './app/views/layouts',
partialsPath: './app/views/partials',
layout: true,
isCached: false
});
server.route(require('./routes'));
server.route(require('./routes-api'));
await server.start();
console.log(`Server running at: ${server.info.uri}`);
}
process.on('unhandledRejection', err => {
console.log(err);
process.exit(1);
});
init();