You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
... # follow the prompts, repeat for `team` and `project`
95
95
```
96
96
97
-
###Define the remote methods
97
+
###Define the remote methods
98
98
99
99
Define three remote methods in [`project.js`](https://github.com/strongloop/loopback-example-access-control/blob/master/common/models/project.js):
@@ -128,7 +128,7 @@ Define three remote methods in [`project.js`](https://github.com/strongloop/loop
128
128
- Property name for the relation: `user`
129
129
- Custom foreign key: `ownerId`
130
130
131
-
###Add model instances
131
+
###Add model instances
132
132
133
133
Create a boot script named [`sample-models.js`](https://github.com/strongloop/loopback-example-access-control/blob/master/server/boot/sample-models.js).
134
134
@@ -143,7 +143,7 @@ This script does the following:
143
143
-[Creates a role named `admin` and adds a role mapping to make `Bob` an
144
144
`admin`](/server/boot/sample-models.js#L50-L65)
145
145
146
-
###Configure server-side views
146
+
###Configure server-side views
147
147
148
148
> LoopBack comes preconfigured with EJS out-of-box. This means we can use
149
149
> server-side templating by simply setting the proper view engine and a
@@ -160,7 +160,7 @@ Create [`index.ejs` in the views directory](https://github.com/strongloop/loopba
160
160
[Configure `server.js`](https://github.com/strongloop/loopback-example-access-control/blob/master/server/server.js#L11-L20) to use server-side
161
161
templating. Remember to import the [`path`](https://github.com/strongloop/loopback-example-access-control/blob/master/server/server.js#L4) package.
162
162
163
-
###Add routes
163
+
###Add routes
164
164
165
165
Create [`routes.js`](https://github.com/strongloop/loopback-example-access-control/blob/master/server/boot/routes.js). This script does the following:
> When you log in sucessfully, `projects.html` is rendered with the authenticated user's access token embedded into each link.
173
173
174
-
###Create the views
174
+
###Create the views
175
175
176
176
Create the [`views` directory](https://github.com/strongloop/loopback-example-access-control/tree/master/server/views) to store views.
177
177
178
178
In this directory, create [`index.ejs`](https://github.com/strongloop/loopback-example-access-control/blob/master/server/views/index.ejs) and [`projects.ejs`](https://github.com/strongloop/loopback-example-access-control/blob/master/server/views/projects.ejs).
> denied. Otherwise, we check to see if the user is a team member and process
187
187
> the request accordingly.
188
188
189
-
###Create ACL entries
189
+
###Create ACL entries
190
190
191
191
> ACLs are used to restrict access to application REST endpoints.
192
192
193
-
####ACL information
193
+
####ACL information
194
194
195
195
- Deny access to all project REST endpoints
196
196
- Select the model to apply the ACL entry to: `(all existing models)`
@@ -236,9 +236,9 @@ $ slc loopback:acl
236
236
# follow the prompts, repeat for each ACL listed above
237
237
```
238
238
239
-
###Try the application
239
+
###Try the application
240
240
241
-
Start the server (`node .`) and open [`localhost:3000`][localhost] in your browser to view the app. You will see logins and explanations related to each user type we created:
241
+
Start the server (`node .`) and open [`localhost:3000`](http://localhost:3000) in your browser to view the app. You will see logins and explanations related to each user type we created:
$ cd loopback-example-rest-connector/external-server
21
21
$ npm install
22
-
# node .
22
+
$ node .
23
23
```
24
24
In another shell:
25
25
```
@@ -35,7 +35,7 @@ explorer or by running `curl localhost:3000/api/Magazines`.
35
35
## FAQs
36
36
The following are common questions related to using the REST connector.
37
37
38
-
##How do you perform a GET request to a remote server?
38
+
##How do you perform a GET request to a remote server?
39
39
In this example, we have a REST API exposed in [model-config.json](https://github.com/strongloop/loopback-example-rest-connector/blob/master/external-server/server/model-config.json#L31)
-[How do you serve static content via static middleware?](https://github.com/strongloop/loopback-example-middleware#how-do-you-serve-static-content-via-static-middleware)
10
10
11
-
#How do you serve static content via static middleware?
11
+
## How do you serve static content via static middleware?
12
12
1. Add static middleware to the [files property](https://github.com/strongloop/loopback-example-middleware/blob/master/server/middleware.json#L17-L19) in middleware.json
4. Start the server via `node .` and browse to [`localhost:3000`](http://localhost:3000). You should see `hello world` being served.
16
16
17
-
18
-
#How do you create a custom error message for all errors?
17
+
## How do you create a custom error message for all errors?
19
18
1. Create a [single function](https://github.com/strongloop/loopback-example-middleware/blob/master/server/server.js#L33-l41) that all errors are passed to.
20
19
2. Set [`app.get('remoting').errorHandler`](https://github.com/strongloop/loopback-example-middleware/blob/master/server/server.js#L23-l31) to call a custom error handler.
21
20
3. Create a [`custom error middleware`](https://github.com/strongloop/loopback-example-middleware/blob/master/server/middleware/custom-error.js) to handle errors not thrown by the `loopback.rest()` middleware.
Copy file name to clipboardExpand all lines: _includes/readmes/loopback-example-mixins.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@ Specify mixin locations relative to the `server/model-config.json` file. Multip
18
18
### npm module
19
19
20
20
This loads the [loopback-ds-timestamp-mixin](https://www.npmjs.com/package/loopback-ds-timestamp-mixin) module from the top level `node_modules` directory. Note that this module provides a mixin file `time-stamp.js` which is registered as the camel case `TimeStamp` name.
21
+
21
22
```js
22
23
{
23
24
"_meta": {
@@ -43,6 +44,7 @@ This loads the [loopback-ds-timestamp-mixin](https://www.npmjs.com/package/loopb
43
44
}
44
45
}
45
46
```
47
+
46
48
### The local `server/mixins/` directory
47
49
48
50
Because the `model-config.json` is within the `server` directory this loads the mixins from current mixins directory.
0 commit comments