-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
40 lines (37 loc) · 879 Bytes
/
server.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
const cuid = require('cuid')
const server = require('./vientos-service')
const Person = require('./vientos-service/src/models/person')
const PWA_URL = process.env.PWA_URL || 'http://localhost:8080'
const handler = function (request, reply) {
let query = Person.findOne({})
if (request.params.id) {
let iri = process.env.OAUTH_CLIENT_DOMAIN + '/people/' + request.params.id
query = Person.findOne({ _id: iri })
}
query.then(person => {
request.cookieAuth.set({
id: person._id,
sessionId: cuid()
})
reply().redirect(PWA_URL + '/me')
})
}
server.route([{
method: 'GET',
path: '/auth/dev',
config: {
auth: false,
handler
}
}, {
method: 'GET',
path: '/auth/dev/{id}',
config: {
auth: false,
handler
}
}])
server.start((err) => {
if (err) throw err
console.log('Server running at:', server.info.uri)
})