mirror of
https://gricad-gitlab.univ-grenoble-alpes.fr/tienyoun/presentations.git
synced 2026-09-26 21:41:08 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import express from 'express'
|
||||
import { createClient } from 'redis';
|
||||
import cors from 'cors'
|
||||
const client = createClient({
|
||||
url: process.env.REDIS_URL
|
||||
});
|
||||
|
||||
client.on('error', err => console.log('Redis Client Error', err));
|
||||
|
||||
await client.connect()
|
||||
|
||||
const app = express()
|
||||
const port = 3000
|
||||
|
||||
app.use(cors())
|
||||
app.use(express.json())
|
||||
|
||||
app.get('/', async (req, res) => {
|
||||
res.send(await client.lRange("messages", 0, -1))
|
||||
})
|
||||
|
||||
app.post('/', async (req, res) => {
|
||||
await client.lPush("messages", JSON.stringify(req.body))
|
||||
res.sendStatus(201)
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`)
|
||||
})
|
||||
Reference in New Issue
Block a user