Giter Site home page Giter Site logo

dwigoric / ccapdev-server-app Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 9.59 MB

Source code for CCAPDEV MCO (Server), Term 3 AY 2022-2023. This API is used by the frontend app that is deployed with code from https://github.com/Dwigoric/CCAPDEV-Web-App.

Home Page: https://compact-donuts.azurewebsites.net

License: GNU General Public License v3.0

JavaScript 100.00%

ccapdev-server-app's Introduction

Compact Donuts - Server

This is the server for the Compact Donuts project. It is a REST API that provides access to the database.

Setup

Before you can run the server, you need to install the dependencies.

npm install

Setup Configuration

Duplicate the .env.example file and rename it to .env. The .env file contains environment variables that are used by the server.

Duplicate the src/config.example.js file and rename it to src/config.js. The src/config.js file contains configuration that is used by the server. You can use this to configure your app's MongoDB connection and other settings.

Running the server

To run the server, you need to run the following command:

npm start

Configuration

All configuration is done through environment variables. You can set these variables in a .env file in the root of the project. Alternatively, you can set them in your shell.

JWT Secret

You can change the JWT secret by setting the JWT_SECRET environment variable. This variable is required to be set. The secret should be a random string of characters. This will be used to sign the JWTs.

Port

You can change the port the server runs on by setting the PORT environment variable. The default port is 3000.

CORS Origin

You can change the CORS origin by setting the FRONTEND_URL environment variable. The default CORS origin is http://localhost:5173. Change the value to Vue's given URL when running the frontend in development, i.e., http://localhost:5173.

Database

This variable is highly recommended to be set. You can change the database the server connects to by setting the MONGODB_URI environment variable. This variable should contain a MongoDB connection string.

The config file's mongodb.name property

The src/config.js file contains a mongodb.name property. This property is used to specify the name of the database. If the .env file's MONGODB_URI variable contains a database name, the mongodb.name property will be prioritized. If the .env file's MONGODB_URI variable does not contain a database name, the mongodb.name property will be used as the database name. If the mongodb.name property is not set, and the .env file's MONGODB_URI variable does not contain a database name, the database name will be set to test.

API

The API is accessible through the root of the server.

Example

If the server is running on localhost:3000, you can access the API by sending a request to http://localhost:3000.

curl http://localhost:3000

ccapdev-server-app's People

Contributors

dwigoric avatar profredacted avatar thea1210 avatar

Watchers

 avatar

ccapdev-server-app's Issues

Backend form validation

Validate all request body data. Implement also for other data. Refer here for which status code is appropriate.

To-do

  • GET /posts - Do validation on last and limit. Both must be numbers. I suggest using the isNaN() function.
  • PATCH /posts/:id - Return a 400 if both title and body are not given. At least one of the two must be supplied.
  • GET /comments/user/:userId - Return a 400 if the user ID given is not in the users database collection.
  • GET /comments/:postId - Return a 400 if the post ID given is not in the posts database collection.
  • GET /comments/:postId/:id - Return a 400 if the post ID given is not in the posts database collection.

Middleware: `/posts`, `/posts/search`, and `/posts/:id`

  • The /posts/:id middleware should be able to handle PATCH and DELETE methods for editing and deleting posts, respectively.
  • The /posts/:id middleware should be able to handle GET method for retrieving specific post.
  • The /posts middleware should be able to handle PUT method for creating a new post.
  • The /posts middleware should be able to handle GET method for retrieving posts in a paginated way.
  • The /posts/search middleware should be able to handle GET method for searching posts.

Middleware: `/comments/:post-id` and `/comments/:post-id/:comment-id`

The /comments/:post-id should be able to handle GET and PUT methods for retrieving post comments and creating a post comment respectively.
The /comments/:post-id/:comment-id middleware should be able to handle PATCH and DELETE methods for editing and deleting comments, respectively.

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.