Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// build an anonymous image:
let builtService = new cloud.Service("examples-nginx2", {
containers: {
nginx: {
build: "./app",
memory: 128,
ports: [{ port: 80 }],
},
},
replicas: 2,
waitForSteadyState: false,
});
// expose some APIs meant for testing purposes.
let api = new cloud.API("examples-containers");
api.get("/test", async (req, res) => {
try {
res.json({
nginx: await nginx.getEndpoint(),
nginx2: await builtService.getEndpoint(),
});
} catch (err) {
console.error(errorJSON(err));
res.status(500).json(errorJSON(err));
}
});
function errorJSON(err: any) {
const result: any = Object.create(null);
Object.getOwnPropertyNames(err).forEach(key => result[key] = err[key]);
return result;
nginx: {
build: "./app",
memory: 128,
loadBalancerPort: {
external: true,
port: 80,
},
},
},
},
desiredCount: 2,
waitForSteadyState: false,
});
// expose some APIs meant for testing purposes.
let api = new cloud.API("examples-containers");
api.get("/test", async (req, res) => {
try {
res.json({
nginx: await nginx.getEndpoint(),
nginx2: await builtService.getEndpoint(),
});
} catch (err) {
console.error(errorJSON(err));
res.status(500).json(errorJSON(err));
}
});
function errorJSON(err: any) {
const result: any = Object.create(null);
Object.getOwnPropertyNames(err).forEach(key => result[key] = err[key]);
return result;
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as cloud from "@pulumi/cloud";
import { Output } from "@pulumi/pulumi";
const api = new cloud.API("examples-test");
api.get("/test1.txt", (req, res) => {
res.setHeader("Content-Type", "text/html");
res.end("You got test1");
});
api.proxy("/google", "http://www.google.com/")
export let url = api.publish().url;
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as cloud from "@pulumi/cloud";
const api = new cloud.API("examples-test");
api.get("/test2.txt", (req, res) => {
res.setHeader("Content-Type", "text/html");
res.end("You got test2");
});
api.publish();