diff options
| author | eug-vs <eug-vs@keemail.me> | 2020-06-08 16:29:43 +0300 | 
|---|---|---|
| committer | eug-vs <eug-vs@keemail.me> | 2020-06-08 16:29:43 +0300 | 
| commit | 977992eb70a0ca3b702e116b628d37ac75e667d1 (patch) | |
| tree | ff436cba6196b889ad25a4345c9b5fb4b335e06c /app.ts | |
| parent | 449726aea3622544cd1ab593c19a36b2a71bd2ae (diff) | |
| download | which-api-977992eb70a0ca3b702e116b628d37ac75e667d1.tar.gz | |
feat: initialize feathers app with PollService
Diffstat (limited to 'app.ts')
| -rw-r--r-- | app.ts | 45 | 
1 files changed, 45 insertions, 0 deletions
@@ -0,0 +1,45 @@ +import feathers from '@feathersjs/feathers'; +import '@feathersjs/transport-commons'; +import express from '@feathersjs/express'; +import socketio from '@feathersjs/socketio'; + +import { PollService } from './PollService'; + +const app = express(feathers()); + +app.use(express.json()); +app.use(express.urlencoded({ extended: true })); +app.use(express.static(__dirname)); +app.configure(express.rest()); +app.configure(socketio()); +app.use(express.errorHandler()); + +app.use('/polls', new PollService()); + + +// Add any new real-time connection to the `everybody` channel +app.on('connection', connection => +  app.channel('everybody').join(connection) +); +// Publish all events to the `everybody` channel +app.publish(data => app.channel('everybody')); + + +app.listen(3030).on('listening', () => +  console.log('Feathers server listening on localhost:3030') +); + +// For good measure let's create a message +// So our API doesn't look so empty +app.service('polls').create({ +  contents: { +    left: { +      url: 'https://github.com/eug-vs.png', +      votes: 10 +    }, +    right: { +      url: 'https://github.com/ilyayudovin.png', +      votes: 15 +    } +  } +});  |