-
Notifications
You must be signed in to change notification settings - Fork 3
/
cloud-run-app.js
41 lines (34 loc) · 860 Bytes
/
cloud-run-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
/**
* Cloud Run application that generates and delivers dynamiocally generated content.
*/
const express = require('express');
const cors = require('cors')
const redis = require("redis");
const app = express();
const client = redis.createClient({
"host": process.env.REDIS_IP
});
client.on("error", function(error) {
console.error(error);
});
app.use(cors());
app.get('/', (req, res) => {
res.set('Cache-Control', 'no-store');
client.set("key", "value!", redis.print);
client.get("key", (err, reply) => {
res.send(`
<html>
<head>
</head>
<body>
<p>Connecting to Redis at: ${process.env.REDIS_IP}</p>
<p>Value of key just read: ${reply}</p>
</body>
</html>
`);
});
});
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});