aboutsummaryrefslogtreecommitdiff
path: root/app.ts
blob: 4a60eb88ddda609fe1ca077d5c63efcb6fe9f9e0 (plain)
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
import feathers from '@feathersjs/feathers';
import '@feathersjs/transport-commons';
import express from '@feathersjs/express';
import socketio from '@feathersjs/socketio';

import { PollService } from './PollService';
import {UserService} from "./UserService";

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());
app.use('/users', new UserService());

// 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
    }
  }
});

app.service('users').create({
  info: {
    name: 'John Doe',
    age: 20,
    nationality: 'Belarus',
    sex: 'male'
  }
});