Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backend example #84

Merged
merged 3 commits into from
Jan 26, 2024
Merged
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
12 changes: 12 additions & 0 deletions examples/backend/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let ignore = [`**/dist`]

// Jest needs to compile this code, but generally we don't want this copied
// to output folders
if (process.env.NODE_ENV !== `test`) {
ignore.push(`**/__tests__`)
}

module.exports = {
presets: [["babel-preset-medusa-package"], ["@babel/preset-typescript"]],
ignore,
}
8 changes: 8 additions & 0 deletions examples/backend/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
JWT_SECRET=something
COOKIE_SECRET=something

DATABASE_TYPE="postgres"
REDIS_URL=redis://localhost:6379

# Your Paystack secret key. See – https://support.paystack.com/hc/en-us/articles/360009881600-Paystack-Test-Keys-Live-Keys-and-Webhooks
PAYSTACK_SECRET_KEY=sk_something
21 changes: 21 additions & 0 deletions examples/backend/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-type: production
groups:
medusa:
patterns:
- "@medusajs*"
- "medusa*"
update-types:
- "minor"
- "patch"
ignore:
- dependency-name: "@medusajs*"
update-types: ["version-update:semver-major"]
- dependency-name: "medusa*"
update-types: ["version-update:semver-major"]
26 changes: 26 additions & 0 deletions examples/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/dist
.env
.DS_Store
/uploads
/node_modules
yarn-error.log

.idea

coverage

!src/**

./tsconfig.tsbuildinfo
package-lock.json
yarn.lock
medusa-db.sql
build
.cache

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
2 changes: 2 additions & 0 deletions examples/backend/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
1 change: 1 addition & 0 deletions examples/backend/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
82 changes: 82 additions & 0 deletions examples/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<p align="center">
<a href="https://www.medusajs.com">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
<img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
</picture>
</a>
</p>
<h1 align="center">
Medusa Paystack Backend Example
</h1>

<h4 align="center">
<a href="https://docs.medusajs.com">Documentation</a> |
<a href="https://www.medusajs.com">Website</a>
</h4>

<p align="center">
Building blocks for digital commerce
</p>
<p align="center">
<a href="https://github.com/medusajs/medusa/blob/master/CONTRIBUTING.md">
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
</a>
<a href="https://www.producthunt.com/posts/medusa"><img src="https://img.shields.io/badge/Product%20Hunt-%231%20Product%20of%20the%20Day-%23DA552E" alt="Product Hunt"></a>
<a href="https://discord.gg/xpCwq3Kfn8">
<img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
</a>
<a href="https://twitter.com/intent/follow?screen_name=medusajs">
<img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
</a>
</p>

## Compatibility

This starter is compatible with versions >= 1.8.0 of `@medusajs/medusa`.

## Getting Started

Visit the [Docs](https://docs.medusajs.com/development/backend/prepare-environment) to learn more about Medusa system requirements.

Visit the [Quickstart Guide](https://docs.medusajs.com/create-medusa-app) to set up the server.

Add your Paystack API keys to the `.env` file.

```bash
PAYSTACK_SECRET_KEY=your_secret_key
```

Run the seed command to seed the database with sample data (optional)

```bash
yarn seed
```

## What is Medusa

Medusa is a set of commerce modules and tools that allow you to build rich, reliable, and performant commerce applications without reinventing core commerce logic. The modules can be customized and used to build advanced ecommerce stores, marketplaces, or any product that needs foundational commerce primitives. All modules are open-source and freely available on npm.

Learn more about [Medusa’s architecture](https://docs.medusajs.com/development/fundamentals/architecture-overview) and [commerce modules](https://docs.medusajs.com/modules/overview) in the Docs.

## Roadmap, Upgrades & Plugins

You can view the planned, started and completed features in the [Roadmap discussion](https://github.com/medusajs/medusa/discussions/categories/roadmap).

Follow the [Upgrade Guides](https://docs.medusajs.com/upgrade-guides/) to keep your Medusa project up-to-date.

Check out all [available Medusa plugins](https://medusajs.com/plugins/).

## Community & Contributions

The community and core team are available in [GitHub Discussions](https://github.com/medusajs/medusa/discussions), where you can ask for support, discuss roadmap, and share ideas.

Join our [Discord server](https://discord.com/invite/medusajs) to meet other community members.

## Other channels

- [GitHub Issues](https://github.com/medusajs/medusa/issues)
- [Twitter](https://twitter.com/medusajs)
- [LinkedIn](https://www.linkedin.com/company/medusajs)
- [Medusa Blog](https://medusajs.com/blog/)
186 changes: 186 additions & 0 deletions examples/backend/data/seed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"store": {
"currencies": ["ghs"],
"default_currency_code": "ghs"
},
"users": [
{
"email": "admin@medusa-test.com",
"password": "supersecret"
}
],
"regions": [
{
"id": "test-region-gh",
"name": "Ghana",
"currency_code": "ghs",
"tax_rate": 0.125,
"payment_providers": ["paystack", "manual"],
"fulfillment_providers": ["manual"],
"countries": ["gh"]
}
],
"shipping_options": [
{
"name": "GhanaPost Standard",
"region_id": "test-region-gh",
"provider_id": "manual",
"data": {
"id": "manual-fulfillment"
},
"price_type": "flat_rate",
"amount": 4500
},
{
"name": "GhanaPost Return",
"region_id": "test-region-gh",
"provider_id": "manual",
"data": {
"id": "manual-fulfillment"
},
"price_type": "flat_rate",
"is_return": true,
"amount": 4500
}
],
"products": [
{
"title": "Medusa Hoodie",
"categories": [
{
"id": "pcat_merch"
}
],
"subtitle": null,
"description": "Reimagine the feeling of a classic hoodie. With our cotton hoodie, everyday essentials no longer have to be ordinary.",
"handle": "hoodie",
"is_giftcard": false,
"weight": 400,
"images": [
"https://medusa-public-images.s3.eu-west-1.amazonaws.com/black_hoodie_front.png",
"https://medusa-public-images.s3.eu-west-1.amazonaws.com/black_hoodie_back.png"
],
"options": [
{
"title": "Size",
"values": ["S", "M", "L", "XL"]
}
],
"variants": [
{
"title": "S",
"prices": [
{
"currency_code": "ghs",
"amount": 12000
}
],
"options": [
{
"value": "S"
}
],
"inventory_quantity": 1000000,
"manage_inventory": true
},
{
"title": "M",
"prices": [
{
"currency_code": "ghs",
"amount": 12000
}
],
"options": [
{
"value": "M"
}
],
"inventory_quantity": 1000000,
"manage_inventory": true
},
{
"title": "L",
"prices": [
{
"currency_code": "ghs",
"amount": 12000
}
],
"options": [
{
"value": "L"
}
],
"inventory_quantity": 1000000,
"manage_inventory": true
},
{
"title": "XL",
"prices": [
{
"currency_code": "ghs",
"amount": 12000
}
],
"options": [
{
"value": "XL"
}
],
"inventory_quantity": 1000000,
"manage_inventory": true
}
]
},
{
"title": "Medusa Coffee Mug",
"categories": [
{
"id": "pcat_merch"
}
],
"subtitle": null,
"description": "Every programmer's best friend.",
"handle": "coffee-mug",
"is_giftcard": false,
"weight": 400,
"images": [
"https://medusa-public-images.s3.eu-west-1.amazonaws.com/coffee-mug.png"
],
"options": [
{
"title": "Size",
"values": ["One Size"]
}
],
"variants": [
{
"title": "One Size",
"prices": [
{
"currency_code": "ghs",
"amount": 5000
}
],
"options": [
{
"value": "One Size"
}
],
"inventory_quantity": 1000000,
"manage_inventory": true
}
]
}
],
"categories": [
{
"id": "pcat_merch",
"name": "Merch",
"rank": 0,
"category_children": [],
"handle": "merch"
}
]
}
50 changes: 50 additions & 0 deletions examples/backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const express = require("express")
const { GracefulShutdownServer } = require("medusa-core-utils")

const loaders = require("@medusajs/medusa/dist/loaders/index").default

;(async() => {
async function start() {
const app = express()
const directory = process.cwd()

try {
const { container } = await loaders({
directory,
expressApp: app
})
const configModule = container.resolve("configModule")
const port = process.env.PORT ?? configModule.projectConfig.port ?? 9000

const server = GracefulShutdownServer.create(
app.listen(port, (err) => {
if (err) {
return
}
console.log(`Server is ready on port: ${port}`)
})
)

// Handle graceful shutdown
const gracefulShutDown = () => {
server
.shutdown()
.then(() => {
console.info("Gracefully stopping the server.")
process.exit(0)
})
.catch((e) => {
console.error("Error received when shutting down the server.", e)
process.exit(1)
})
}
process.on("SIGTERM", gracefulShutDown)
process.on("SIGINT", gracefulShutDown)
} catch (err) {
console.error("Error starting server", err)
process.exit(1)
}
}

await start()
})()
Loading
Loading