forked from Giveth/feathers-giveth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
93 lines (80 loc) · 2.54 KB
/
app.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
81
82
83
84
85
86
87
88
89
90
91
92
93
const logger = require('winston');
const path = require('path');
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const helmet = require('helmet');
const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const configuration = require('@feathersjs/configuration');
const socketsConfig = require('./socketsConfig');
const configureLogger = require('./utils/configureLogger');
const middleware = require('./middleware');
const services = require('./services');
const appHooks = require('./app.hooks');
const authentication = require('./authentication');
const blockchain = require('./blockchain');
const mongoose = require('./mongoose');
const ipfsFetcher = require('./utils/ipfsFetcher');
const ipfsPinner = require('./utils/ipfsPinner');
const channels = require('./channels');
const app = express(feathers());
function initFeatherApp() {
// Load app configuration
app.configure(configuration());
app.configure(configureLogger);
app.use(cors());
app.use(helmet());
app.use(compress());
app.use(express.json({ limit: '10mb' }));
app.use(
express.urlencoded({
limit: '10mb',
extended: true,
}),
);
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
// Host the public folder
app.use('/', express.static(app.get('public')));
app.configure(mongoose);
app.configure(express.rest());
app.configure(socketsConfig);
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
app.configure(authentication);
// Set up our services (see `services/index.js`)
app.configure(services);
app.configure(channels);
// blockchain must be initialized after services
app.configure(blockchain);
app.configure(ipfsFetcher);
app.configure(ipfsPinner);
// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use(
express.errorHandler({
logger: {
error: e => {
if (e.name === 'NotFound') {
logger.warn(`404 - NotFound - ${e.data.url}`);
} else {
logger.error('Express error handler:', e);
}
},
info: e => {
if (e.name === 'NotFound') {
logger.warn(`404 - NotFound - ${e.data.url}`);
} else {
logger.error('Express error handler:', e);
}
},
},
}),
);
app.hooks(appHooks);
return app;
}
function getFeatherAppInstance() {
return app;
}
module.exports = { initFeatherApp, getFeatherAppInstance };