-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathserver.js
More file actions
143 lines (116 loc) · 3.27 KB
/
Copy pathserver.js
File metadata and controls
143 lines (116 loc) · 3.27 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright IBM Corp. 2015,2016. All Rights Reserved.
// Node module: loopback-workspace
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var loopback = require('loopback');
var path = require('path');
var methodOverride = require('method-override');
var app = module.exports = loopback();
var boot = require('loopback-boot');
var cookieParser = require('cookie-parser');
var errorHandler = require('strong-error-handler');
app.set('legacyExplorer', false);
// required to support base models
app.dataSource('db', {
connector: loopback.Memory,
defaultForType: 'db',
});
// must define base models first
// see: https://github.com/strongloop/loopback/issues/324
// require('./models/workspace-entity');
// require('./models/definition');
/*
* 1. Configure LoopBack models and datasources
*
* Read more at http://apidocs.strongloop.com/loopback#appbootoptions
*/
boot(app, __dirname);
// file persistence
require('./connector');
app.emit('ready');
/*
* 2. Configure request preprocessing
*
* LoopBack support all express-compatible middleware.
*/
app.use(loopback.favicon());
app.use(cookieParser(app.get('cookieSecret')));
app.use(methodOverride());
/*
* EXTENSION POINT
* Add your custom request-preprocessing middleware here.
* Example:
* app.use(loopback.limit('5.5mb'))
*/
/*
* 3. Setup request handlers.
*/
// LoopBack REST interface
app.use(app.get('restApiRoot'), loopback.rest());
// API explorer
require('loopback-component-explorer')(app);
app.once('started', function(baseUrl) {
console.log('Browse your REST API at %s%s', baseUrl, '/explorer');
});
/*
* EXTENSION POINT
* Add your custom request-handling middleware here.
* Example:
* app.use(function(req, resp, next) {
* if (req.url == '/status') {
* // send status response
* } else {
* next();
* }
* });
*/
// The static file server should come after all other routes
// Every request that goes through the static middleware hits
// the file system to check if a file exists.
app.use(loopback.static(path.join(__dirname, 'public')));
// Requests that get this far won't be handled
// by any middleware. Convert them into a 404 error
// that will be handled later down the chain.
app.use(loopback.urlNotFound());
/*
* 4. Setup error handling strategy
*/
/*
* EXTENSION POINT
* Add your custom error reporting middleware here
* Example:
* app.use(function(err, req, resp, next) {
* console.log(req.url, ' failed: ', err.stack);
* next(err);
* });
*/
// The ultimate error handler.
app.use(errorHandler());
/*
* 5. Add a basic application status route at the root `/`.
*
* (remove this to handle `/` on your own)
*/
app.get('/', loopback.status());
/*
* 6. Enable access control and token based authentication.
*/
var swaggerRemote = app.remotes().exports.swagger;
if (swaggerRemote) {
swaggerRemote.requireToken = false;
}
/*
* 7. Optionally start the server
*
* (only if this module is the main module)
*/
app.start = function() {
return app.listen(function() {
var baseUrl = 'http://' + app.get('host') + ':' + app.get('port');
app.emit('started', baseUrl);
console.log('LoopBack server listening @ %s%s', baseUrl, '/');
});
};
if (require.main === module) {
app.start();
}