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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MONGO_URI=mongodb://localhost:27017/help-center-api
18 changes: 18 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Help Center API

## Description

This is a RESTful API for managing Help Center cards.

## Setup

1. Clone the repository.
2. Run `npm install` to install dependencies.
3. Create a `.env` file with your MongoDB connection string (example: `MONGO_URI=mongodb://localhost:27017/help-center-api`).
4. Run `npm start` to start the server.

## API Endpoints

- `POST /cards`: Create a new card.
- `GET /cards`: Retrieve all cards.
- `GET /cards/:title`: Retrieve a card by its title.
36 changes: 36 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const express = require("express");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const cardRoutes = require("./routes/cards");
const cors = require("cors");

dotenv.config();

const app = express();
const PORT = process.env.PORT || 5000;

// Middleware
app.use(cors()); // Configure CORS before other middleware
app.use(express.json());

// Connect to MongoDB
mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Connected to MongoDB");
})
.catch((err) => console.error("MongoDB connection error:", err));

// Routes
app.get("/ping", (req, res) => res.send("Server is running!"));
app.use("/cards", cardRoutes);

// Error handling
app.use((err, req, res, next) => {
res.status(err.status || 500).json({ error: err.message });
});

app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
9 changes: 9 additions & 0 deletions backend/models/Card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const mongoose = require("mongoose");

const cardSchema = new mongoose.Schema({
title: { type: String, required: true, unique: true },
description: { type: String, required: true },
});

const Card = mongoose.model("Card", cardSchema);
module.exports = Card;
16 changes: 16 additions & 0 deletions backend/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions backend/node_modules/.bin/mime.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions backend/node_modules/.bin/mime.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading