Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

Copy paste following markdown into your markdown content, and that's it. Easy Easy Tammam Tammam!

Change the `?userID=` value to your StackOverflow's userID.
Change the `?userID=` value to your StackExchange userID (for the relevant site).

```md
[![Omid Nikrah StackOverflow](https://github-readme-stackoverflow.vercel.app/?userID=6558042)](https://stackoverflow.com/users/6558042/omid-nikrah)
Expand All @@ -28,21 +28,38 @@ If you want to have a compact layout, just you need to add `layout=compact` as a
[![Omid Nikrah StackOverflow](https://github-readme-stackoverflow.vercel.app/?userID=6558042&layout=compact)](https://stackoverflow.com/users/6558042/omid-nikrah)
[![Omid Nikrah StackOverflow](https://github-readme-stackoverflow.vercel.app/?userID=6558042&layout=compact&theme=dark)](https://stackoverflow.com/users/6558042/omid-nikrah)

#### Other Sites

You can use other StackExchange sites instead of StackOverflow too, such as Biology StackExchange or AskUbuntu. Just add `site={SITE}` as a parameter. Examples:
- `site=biology`
- `site=askubuntu`
- `site=money`

The site name provided as a parameter must be the same as the domain for that site. For example, Personal Finance and Money StackExchange has a URL of `money.stackexchange.com`, so `site=money` must be provided.

> **Warning**
> Different sites have different userIDs. So your StackOverflow userID will not be the same as your Biology StackExchange userID.

[![Zohan Subhash Biology.SE](https://github-readme-stackoverflow.zohan.tech/?userID=68669&site=biology)](https://biology.stackexchange.com/users/68669/zo-bro-23)
[![Zohan Subhash Biology.SE](https://github-readme-stackoverflow.zohan.tech/?userID=68669&theme=dark&site=biology)](https://biology.stackexchange.com/users/68669/zo-bro-23)

<br>

## Options
| Name | Description | Default value |
| ---------- | ------------------------------- | -------------------------- |
| userID | Your StackOverflow userID | REQUIRED |
| userID | Your StackExchange userID | REQUIRED |
| theme | Theme of the StackOverflow card (light or dark) | light |
| layout | Layout of the StackOverflow card (compact or default) | default |
| layout | Layout of the StackOverflow card (compact or default) | default |
| site | Which StackExchange site to get the data from | stackoverflow |

<br>

## Contributors
- [Omid Nikrah](https://github.com/omidnikrah)
- [Soroush Chehresa](https://github.com/soroushchehresa)
- [Zohan Subhash](https://github.com/Zo-Bro-23)
- [Jéf Bueno](https://github.com/jfbueno)

<br>

Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ const StackOverflowCard = require('./src/StackOverflowCard');

http.createServer(async (req, res) => {
const reqURL = url.parse(req.url, true);
const { userID, theme = 'light', layout = 'default' } = reqURL.query;
const { userID, theme = 'light', layout = 'default', site = 'stackoverflow' } = reqURL.query;

if (!userID) {
res.write(JSON.stringify({error: 'Add your StackOverflow userID as query string'}));
res.end();
return;
}

const responseArticles = await fetch(`https://api.stackexchange.com/2.2/users/${userID}?site=stackoverflow&filter=!--1nZv)deGu1`);
const responseArticles = await fetch(`https://api.stackexchange.com/2.2/users/${userID}?site=${site}&filter=!--1nZv)deGu1`);
const json = await responseArticles.json();

if (!json.items || json.items.length === 0) {
res.write(JSON.stringify({error: 'Your stackoverflow userID is not correct'}));
res.write(JSON.stringify({error: 'Your userID/site is not valid'}));
res.end();
return;
}
Expand All @@ -33,4 +33,4 @@ http.createServer(async (req, res) => {
res.end();
}).listen(process.env.PORT || 3000, function(){
console.log("server start at port 3000");
});
});
11 changes: 9 additions & 2 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"version": 2,
"builds": [{
"src": "index.js",
"use": "@now/node-server"
}]
"use": "@vercel/node"
}],
"routes": [
{
"src": "/(.*)",
"dest": "index.js"
}
]
}