Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit e35a235

Browse files
committed
new hosted targets exmaples
1 parent ac8fcd2 commit e35a235

File tree

16 files changed

+387
-0
lines changed

16 files changed

+387
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This directory contains samples that you can deploy on Apigee Edge Hosted Targets. See the README files for detailed instructions.
2+
3+
To learn about Hosted Targets, see [Hosted Targets overview](https://docs.apigee.com/api-platform/hosted-targets/hosted-targets-overview.html) in the Apigee Edge documentation.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# How to create a hello world Node.js application with Hosted Targets using express
2+
3+
This sample is a Node.js proxy that uses [express](https://www.npmjs.com/package/express).
4+
5+
## Test the app locally
6+
Before pushing to Apigee, it can be useful to test the application locally first to make sure everything is working as it should.
7+
8+
1. Make sure you have [Nodejs](https://nodejs.org/en/download/) installed
9+
2. Installl dependencies:
10+
11+
```
12+
cd apiproxy/resources/hosted
13+
npm install
14+
```
15+
16+
3. Start the application:
17+
18+
```
19+
PORT=8081 node index.js
20+
```
21+
22+
4. Test the applicaiton:
23+
24+
```
25+
curl http://localhost:8081
26+
{"hello":"Hello World!"}
27+
28+
curl http://localhost:8081/hello/user
29+
{"hello":"hello user"}
30+
```
31+
32+
5. Remove node_modules and package-lock.json:
33+
34+
```
35+
rm -rf node_modules
36+
rm package-lock.json
37+
```
38+
39+
6. Go back to the home directory for deploying:
40+
41+
```
42+
cd ../../..
43+
```
44+
45+
## Deploy the proxy
46+
1. Make sure you have [apigeetool](https://github.com/apigee/apigeetool-node) installed
47+
2. Make sure you have [get_token](https://apidocs.apigee.com/api-reference/content/using-oauth2-security-apigee-edge-management-api) script installed
48+
3. Deploy your proxy:
49+
50+
```
51+
get_token && apigeetool deployproxy \
52+
-o <apigee org> \
53+
-e <apigee env> \
54+
--json \
55+
--token "$(< ~/.sso-cli/valid_token.dat)" \
56+
--api node-hosted-express \
57+
--directory .
58+
```
59+
**Note**: This step might take a minute or two to work
60+
61+
4. Test your proxy deployment:
62+
63+
```
64+
curl https:/<apigee org>-<apigee env>.apigee.net/node-hosted-express
65+
```
66+
67+
5. Undeploy your proxy:
68+
69+
```
70+
get_token && apigeetool undeploy \
71+
-o <apigee org> \
72+
-e <apigee env> \
73+
--json \
74+
--token "$(< ~/.sso-cli/valid_token.dat)" \
75+
--api node-hosted-express \
76+
--revision <revision to undeploy e.g 1>
77+
```
78+
79+
For more insight into Hosted Targets and Apigee, visit our [documentation](https://docs.apigee.com/api-platform/hosted-targets/hosted-targets-overview.html).
80+
81+
# Ask the community
82+
83+
[![alt text](../../images/apigee-community.png "Apigee Community is a great place to ask questions and find answers about developing API proxies. ")](https://community.apigee.com?via=github)
84+
85+
---
86+
87+
Copyright © 2017 Apigee Corporation
88+
89+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
90+
this file except in compliance with the License. You may obtain a copy
91+
of the License at
92+
93+
http://www.apache.org/licenses/LICENSE-2.0
94+
95+
Unless required by applicable law or agreed to in writing, software
96+
distributed under the License is distributed on an "AS IS" BASIS,
97+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
98+
See the License for the specific language governing permissions and
99+
limitations under the License.
100+
101+
http://docs.apigee.com/api-services/reference/supported-software
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<APIProxy revision="1" name="node-hosted-express">
3+
<Basepaths>/node-hosted-express</Basepaths>
4+
<ConfigurationVersion majorVersion="4" minorVersion="0"/>
5+
<CreatedAt>1512506918706</CreatedAt>
6+
<CreatedBy>[email protected]</CreatedBy>
7+
<Description></Description>
8+
<DisplayName>node-hosted-express</DisplayName>
9+
<LastModifiedAt>1512506918706</LastModifiedAt>
10+
<LastModifiedBy>[email protected]</LastModifiedBy>
11+
<Policies/>
12+
<ProxyEndpoints>
13+
<ProxyEndpoint>default</ProxyEndpoint>
14+
</ProxyEndpoints>
15+
<Resources>
16+
<Resource>hosted://app.yaml</Resource>
17+
<Resource>hosted://index.js</Resource>
18+
<Resource>hosted://package.json</Resource>
19+
</Resources>
20+
<Spec></Spec>
21+
<TargetServers/>
22+
<TargetEndpoints>
23+
<TargetEndpoint>default</TargetEndpoint>
24+
</TargetEndpoints>
25+
</APIProxy>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<ProxyEndpoint name="default">
3+
<Description/>
4+
<FaultRules/>
5+
<PreFlow name="PreFlow">
6+
<Request/>
7+
<Response/>
8+
</PreFlow>
9+
<PostFlow name="PostFlow">
10+
<Request/>
11+
<Response/>
12+
</PostFlow>
13+
<Flows/>
14+
<HTTPProxyConnection>
15+
<BasePath>/node-hosted-express</BasePath>
16+
<Properties/>
17+
<VirtualHost>default</VirtualHost>
18+
<VirtualHost>secure</VirtualHost>
19+
</HTTPProxyConnection>
20+
<RouteRule name="default">
21+
<TargetEndpoint>default</TargetEndpoint>
22+
</RouteRule>
23+
</ProxyEndpoint>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
runtime: node
2+
runtimeVersion: 8
3+
application: my-express-app
4+
env:
5+
- name: NODE_ENV
6+
value: production
7+
- name: LOG_LEVEL
8+
value: 3
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var express = require('express')
2+
var app = express()
3+
4+
app.get('/', function (req, res) {
5+
res.json({ hello: "Hello World!" })
6+
})
7+
8+
app.get('/hello/:name', function (req, res) {
9+
var name = req.params.name
10+
res.json({ hello: "hello " + name })
11+
})
12+
13+
var server = app.listen(process.env.PORT || 9000, function () {
14+
console.log('Listening on port %d', server.address().port)
15+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "hello-world",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"start": "node index.js --use_strict"
7+
},
8+
"author": "",
9+
"license": "",
10+
"dependencies": {
11+
"express": "^4.16.0"
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<TargetEndpoint name="default">
3+
<Description/>
4+
<FaultRules/>
5+
<PreFlow name="PreFlow">
6+
<Request/>
7+
<Response/>
8+
</PreFlow>
9+
<PostFlow name="PostFlow">
10+
<Request/>
11+
<Response/>
12+
</PostFlow>
13+
<Flows/>
14+
<HostedTarget/>
15+
</TargetEndpoint>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
get_token && apigeetool deployproxy \
2+
-o apigee-hf-testing \
3+
-e test \
4+
--json \
5+
--token "$(< ~/.sso-cli/valid_token.dat)" \
6+
--api node-hosted-express \
7+
--directory .
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# How to create a hello world Node.js application with Hosted Targets
2+
3+
This sample is a simple hello world Node.js proxy.
4+
5+
## Test the app locally
6+
Before pushing to Apigee, it can be useful to test the application locally first to make sure everything is working as it should.
7+
8+
1. Make sure you have [Nodejs](https://nodejs.org/en/download/) installed
9+
10+
2. Start the application:
11+
12+
```
13+
PORT=8081 node apiproxy/resources/hosted/index.js
14+
```
15+
16+
3. Test the applicaiton:
17+
18+
```
19+
curl http://localhost:8081
20+
{"date":"2018-03-12T21:45:22.161Z","msg":"Hello, World!"}
21+
```
22+
23+
## Deploy the proxy
24+
1. Make sure you have [apigeetool](https://github.com/apigee/apigeetool-node) installed
25+
2. Make sure you have [get_token](https://apidocs.apigee.com/api-reference/content/using-oauth2-security-apigee-edge-management-api) script installed
26+
3. Deploy your proxy:
27+
28+
```
29+
get_token && apigeetool deployproxy \
30+
-o <apigee org> \
31+
-e <apigee env> \
32+
--json \
33+
--token "$(< ~/.sso-cli/valid_token.dat)" \
34+
--api node-hosted-hello \
35+
--directory .
36+
```
37+
**Note**: This step might take a minute or two to work
38+
39+
4. Test your proxy deployment:
40+
41+
```
42+
curl https:/<apigee org>-<apigee env>.apigee.net/node-hosted-hello
43+
```
44+
45+
5. Undeploy your proxy:
46+
47+
```
48+
get_token && apigeetool undeploy \
49+
-o <apigee org> \
50+
-e <apigee env> \
51+
--json \
52+
--token "$(< ~/.sso-cli/valid_token.dat)" \
53+
--api node-hosted-hello \
54+
--revision <revision to undeploy e.g 1>
55+
```
56+
57+
For more insight into Hosted Targets and Apigee, visit our [documentation](https://docs.apigee.com/api-platform/hosted-targets/hosted-targets-overview.html).
58+
59+
# Ask the community
60+
61+
[![alt text](../../images/apigee-community.png "Apigee Community is a great place to ask questions and find answers about developing API proxies. ")](https://community.apigee.com?via=github)
62+
63+
---
64+
65+
Copyright © 2017 Apigee Corporation
66+
67+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
68+
this file except in compliance with the License. You may obtain a copy
69+
of the License at
70+
71+
http://www.apache.org/licenses/LICENSE-2.0
72+
73+
Unless required by applicable law or agreed to in writing, software
74+
distributed under the License is distributed on an "AS IS" BASIS,
75+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
76+
See the License for the specific language governing permissions and
77+
limitations under the License.
78+
79+
http://docs.apigee.com/api-services/reference/supported-software

0 commit comments

Comments
 (0)