This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Redis example to use Tailwind. (vercel#23131)
And an improved design 😄 https://roadmap-redis.vercel.app/
- Loading branch information
Showing
28 changed files
with
379 additions
and
443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Redis from 'ioredis' | ||
|
||
const redis = new Redis(process.env.REDIS_URL) | ||
|
||
export default redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
{ | ||
"name": "with-redis", | ||
"version": "0.1.1", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"ioredis": "^4.22.0", | ||
"autoprefixer": "^10.0.4", | ||
"clsx": "^1.1.1", | ||
"ioredis": "^4.23.0", | ||
"next": "latest", | ||
"react": "17.0.1", | ||
"react-dom": "17.0.1", | ||
"react-toastify": "^6.0.8" | ||
"postcss": "^8.1.10", | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1", | ||
"react-hot-toast": "^1.0.2", | ||
"swr": "^0.5.1", | ||
"tailwindcss": "^2.0.2", | ||
"uuid": "^8.3.2" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^2.2.1" | ||
"@tailwindcss/jit": "0.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
import './index.css' | ||
import 'react-toastify/dist/ReactToastify.css' | ||
import '../styles/globals.css' | ||
import { Toaster } from 'react-hot-toast' | ||
|
||
// This default export is required in a new `pages/_app.js` file. | ||
export default function MyApp({ Component, pageProps }) { | ||
return <Component {...pageProps} /> | ||
function MyApp({ Component, pageProps }) { | ||
return ( | ||
<> | ||
<Component {...pageProps} /> | ||
<Toaster | ||
position="bottom-right" | ||
toastOptions={{ | ||
style: { | ||
margin: '40px', | ||
background: '#363636', | ||
color: '#fff', | ||
zIndex: 1, | ||
}, | ||
duration: 5000, | ||
}} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default MyApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
import { getRedis } from './utils' | ||
import { v4 as uuidv4 } from 'uuid' | ||
|
||
import redis from '../../lib/redis' | ||
|
||
export default async function upvote(req, res) { | ||
const { title } = req.body | ||
|
||
module.exports = async (req, res) => { | ||
let redis = getRedis() | ||
const body = req.body | ||
const title = body['title'] | ||
if (!title) { | ||
redis.quit() | ||
res.json({ | ||
res.status(400).json({ | ||
error: 'Feature can not be empty', | ||
}) | ||
} else if (title.length < 70) { | ||
await redis.zadd('roadmap', 'NX', 1, title) | ||
redis.quit() | ||
res.json({ | ||
} else if (title.length < 150) { | ||
const id = uuidv4() | ||
const newEntry = { | ||
id, | ||
title, | ||
created_at: Date.now(), | ||
score: 1, | ||
ip: 'NA', | ||
} | ||
|
||
await redis.hset('features', id, JSON.stringify(newEntry)) | ||
res.status(200).json({ | ||
body: 'success', | ||
}) | ||
} else { | ||
redis.quit() | ||
res.json({ | ||
error: 'Max 70 characters please.', | ||
res.status(400).json({ | ||
error: 'Max 150 characters please.', | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import redis from '../../lib/redis' | ||
|
||
export default async function upvote(req, res) { | ||
const features = (await redis.hvals('features')) | ||
.map((entry) => JSON.parse(entry)) | ||
.sort((a, b) => b.score - a.score) | ||
|
||
res.status(200).json({ features }) | ||
} |
This file was deleted.
Oops, something went wrong.
19 changes: 5 additions & 14 deletions
19
examples/with-redis/pages/api/addemail.js → examples/with-redis/pages/api/subscribe.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import { getRedis } from './utils' | ||
import redis from '../../lib/redis' | ||
|
||
module.exports = async (req, res) => { | ||
let redis = getRedis() | ||
const body = req.body | ||
const title = body['title'] | ||
let ip = req.headers['x-forwarded-for'] || req.headers['Remote_Addr'] || 'NA' | ||
let c = ip === 'NA' ? 1 : await redis.sadd('s:' + title, ip) | ||
if (c === 0) { | ||
redis.quit() | ||
res.json({ | ||
export default async function upvote(req, res) { | ||
const { title, id } = req.body | ||
const ip = | ||
req.headers['x-forwarded-for'] || req.headers['Remote_Addr'] || 'NA' | ||
const count = ip === 'NA' ? 1 : await redis.sadd('s:' + title, ip) | ||
|
||
if (count === 0) { | ||
res.status(400).json({ | ||
error: 'You can not vote an item multiple times', | ||
}) | ||
} else { | ||
let v = await redis.zincrby('roadmap', 1, title) | ||
redis.quit() | ||
res.json({ | ||
body: v, | ||
}) | ||
const entry = JSON.parse((await redis.hget('features', id)) || 'null') | ||
const updated = { | ||
...entry, | ||
score: entry.score + 1, | ||
ip, | ||
} | ||
|
||
await redis.hset('features', id, JSON.stringify(updated)) | ||
return res.status(201).json(updated) | ||
} | ||
} |
Oops, something went wrong.