Git Product home page Git Product logo

stackoverflow-clone's Introduction

Stackoverflow Clone

This project is a simplified a full stack clone of Stackoverflow. I wrote it to learn more about Nodejs, React/Next, pixel perfect design and NoSQL databases in general. Feel free to contribute!

๐Ÿš€ Tech Stack

  • ReactJs
  • NextJs
  • Storybook
  • PostCSS
  • NodeJs
  • Express
  • MongoDB
  • Mongoose

โš ๏ธ Prerequisite

  • node
  • npm
  • mongodb

๐Ÿ’ฟ How to run local

# Clone this repository
$ git clone https://github.com/salihozdemir/stackoverflow-clone

# Go into the repository
$ cd stackoverflow-clone

# Go into server
$ cd server

# Start mongodb locally
$ mongod

# Install dependencies
$ npm install

# Start the backend server
$ npm run dev

# On another terminal, go to the client folder
$ cd ../client

# Install dependencies
$ npm install

# Use the command below for Android devices
$ npm run dev

# To see the incomplete storybook components
npm run storybook

๐Ÿ”Ž Testing

Make sure mongodb is running before testing the server.

$ cd server
$ yarn test

There are missing tests on the server side and there are no tests on the client side yet.

๐ŸŒ Deploy

Deploying Server App on Heroku

  • You will need to have setup a MongoDB Atlas account and database.

  • Make sure that the cluster has allowlisted connections from anywhere.

  • Create a Heroku new app.

  • Go to app settings

  • Add the following enviroments.

    • DATABASE_URL (to use your MongoDB connection string)
    • JWT_SECRET
  • Add Nodejs to buildpacks

  •   # Go into the repository
      $ cd stackoverflow-clone
    
      # Heroku Setup
      $ npm install -g heroku
      $ heroku login
      $ heroku git:remote -a your-app-name
    
      # push subdirectory repository with subtree
      $ git subtree push --prefix server heroku master
    

Deploying Client App on Vercel

  • Deploy with Vercel

  • Select client directory

  • Add heroku api url to SITE_NAME enviorement

  • Finally deploy client application

๐Ÿ“œ Todo

  • Add missing components to storybook
  • Complete missing server tests
  • Add text editor for post

๐Ÿ“ License

This project is made available under the MIT License.

stackoverflow-clone's People

Contributors

dejvid98 avatar dependabot[bot] avatar salihozdemir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stackoverflow-clone's Issues

Setting basePath for Next

I am unable to get the application to use a basePath parameter supplied in the next.config.js file:

adding

module.exports = { basePath: '/somepath' ...

doesn't seem to have any effect

Changing the name of the project

Hello,

First of all, "ellerine saฤŸlฤฑk", the project is great!

I think changing the name into something else (maybe another error like segmentation fault to keep the joke) would be better, because this project may be easily turned into a self-hosted version of Stack Overflow (actually a self-hosted Q&A platform) and may be used by organizations or projects that need such solution.

Best regards,

Error: Request failed with status code 500

I try to test stackoverflow-clone on local with Linux, but I have this alert in the page, instead of the database content.

Screen Shot 2021-09-14 at 12 01 40 AM

Unhandled Runtime Error

Error: Request failed with status code 500
Call Stack
createError
node_modules/axios/lib/core/createError.js (16:0)
settle
node_modules/axios/lib/core/settle.js (17:0)
handleLoad
node_modules/axios/lib/adapters/xhr.js (61:0)

API does not verify JWT tokens

Problem

When you decode the provided JWT token to authorize the request, you're not checking whether the JWT token is genuine; that it was signed by you, and the contents are valid.

const decodedToken = jwtDecode(token.slice(7));
if (!decodedToken) {
return res.status(401).json({
message: 'There was a problem authorizing the request.'
});
} else {
req.user = decodedToken;
next();
}

This means that I could create my own token, pretending to be any user I like, and your server won't check to see if it's a forgery.

I could also create a token that contains { role: "admin" } and do whatever an admin can do:

if (req.question.author._id.equals(req.user.id) || req.user.role === 'admin') return next();

This is also a problem in your reddit-clone repo

Example

For example, this completely fake & unsigned JWT token I made myself:

e30.eyJpZCI6MSwidXNlcm5hbWUiOiJhbGljZSIsInJvbGUiOiJhZG1pbiJ9

Which contains this fake data:

{
    id: 1,
    username: "alice",
    role: "admin"
}

Would allow me to bypass your requireAuth middleware.

Documentation

The library you're using to do this (jwt-decode) has a large warning about this on its README:

jwt-decode is a small browser library that helps decoding JWTs token which are Base64Url encoded.

IMPORTANT: This library doesn't validate the token, any well formed JWT can be decoded. You should validate the token in your server-side logic by using something like express-jwt, koa-jwt, Owin Bearer JWT, etc.

How do you create this clone?

First Congratulations for your work, I'm trying to get better at front end and react. I'm trying to understand how is the process do you take when you clone?

mongoose

DeprecationWarning: Listening to events on the Db class has been deprecated and will be removed in the next major version

Get Cors error while trying first setup

Seems server side not started successfully

Unhandled Runtime Error
Error: Network Error

Call Stack
createError
node_modules/axios/lib/core/createError.js (16:0)
XMLHttpRequest.handleError
node_modules/axios/lib/adapters/xhr.js (83:0)

a-nai@a-nai:~/stackoverflow-clone/server$ sudo npm run start

[email protected] start /home/a-nai/stackoverflow-clone/server
node index.js

at http://84.201.145.163:8080 i get
{"message":"Not found"}

Creating the same clone based on firebase

Hey there! I am new to programming and I know only firebase... Could you create the same clone ( all the files should be same) but only replace mongodb with firebase?

Connect to atlas mongodb

I create the cluster, the user and then allowing all IPs to have access to my cluster. I press connect to get the application string and change the with my password leaving the default database myFirst Database. When I paste the string to the DATABASE_URL variable and then press deploy I get {"message":"Not found"}. What am I doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.