-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.mjs
46 lines (38 loc) · 1.19 KB
/
server.mjs
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
import { feathers } from '@feathersjs/feathers'
import express from '@feathersjs/express'
import socketio from '@feathersjs/socketio'
import { MemoryService } from '@feathersjs/memory'
import { Service } from '../lib/service.js'
import _ from 'lodash'
const port = process.env.PORT || 8081
// Create the Feathers app
const app = express(feathers())
// Configure express
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
// Configure Socket.io
app.configure(socketio({
cors: { origin: '*' },
maxHttpBufferSize: 1e8
}))
// Configure user service
class UserService extends MemoryService {}
app.use('users', new UserService({ multi: ['remove'] }))
// Define the options used to instanciate the webpush service
const options = {
vapidDetails: {
subject: process.env.VAPID_SUBJECT,
publicKey: process.env.VAPID_PUBLIC_KEY,
privateKey: process.env.VAPID_PRIVATE_KEY
},
app: app
}
// Register webpush service on the Feathers application
// /!\ do not forget to declare the custom methods
app.use('push', new Service(options), {
methods: ['create']
})
// Start the server
app.listen(port).then(() => {
console.log(`Feathers server listening on localhost:${port}`)
})