Skip to content

Commit

Permalink
adding dist folder for deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
andrenormanlang committed Aug 29, 2024
1 parent 6d436c5 commit 75f2a78
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local


# env files
.env
Expand Down
68 changes: 68 additions & 0 deletions dist/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const http_1 = __importDefault(require("http"));
const dotenv = __importStar(require("dotenv"));
const app_1 = __importDefault(require("./src/app"));
dotenv.config();
// Read port to start server on from `.env`, otherwise default to port 3000
const PORT = process.env.API_URL || 3000;
/**
* Create HTTP server.
*/
const server = http_1.default.createServer(app_1.default);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(PORT);
/**
* Event listener for HTTP server "error" event.
*/
server.on('error', (err) => {
if (err.syscall !== 'listen') {
throw err;
}
switch (err.code) {
case 'EACCES':
console.error(`🦸🏻 Port ${PORT} requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
console.error(`🛑 Port ${PORT} is already in use`);
process.exit(1);
break;
default:
throw err;
}
});
/**
* Event listener for HTTP server "listening" event.
*/
server.on('listening', () => {
console.log(`🧑🏻‍🍳 Yay, server started on http://localhost:${PORT}`);
});
15 changes: 15 additions & 0 deletions dist/src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const morgan_1 = __importDefault(require("morgan"));
const api_1 = __importDefault(require("./routes/api"));
const app = (0, express_1.default)();
// Middleware setup
app.use(express_1.default.json());
app.use((0, morgan_1.default)("dev"));
// Route handling
app.use("/api", api_1.default);
exports.default = app;
8 changes: 8 additions & 0 deletions dist/src/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.db = void 0;
require("dotenv/config");
const neon_http_1 = require("drizzle-orm/neon-http");
const serverless_1 = require("@neondatabase/serverless");
const sql = (0, serverless_1.neon)(process.env.DATABASE_URL);
exports.db = (0, neon_http_1.drizzle)(sql);
119 changes: 119 additions & 0 deletions dist/src/routes/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const db_1 = require("../db");
const schema_1 = require("../schema");
const drizzle_orm_1 = require("drizzle-orm");
const router = (0, express_1.Router)();
/**
* Get all cards
*/
router.get("/cards", async (_req, res) => {
try {
const cards = await db_1.db.select().from(schema_1.tarotCards);
res.json(cards);
}
catch (error) {
console.error("Error fetching cards:", error);
res.status(500).json({ message: "Internal server error" });
}
});
/**
* Get a card by ID
*/
router.get("/cards/:id", async (req, res) => {
try {
const card = await db_1.db
.select()
.from(schema_1.tarotCards)
.where((0, drizzle_orm_1.eq)(schema_1.tarotCards.id, parseInt(req.params.id, 10)))
.limit(1);
if (card.length === 0) {
res.status(404).json({ message: "Card not found" });
}
else {
res.json(card[0]);
}
}
catch (error) {
console.error("Error fetching card:", error);
res.status(500).json({ message: "Internal server error" });
}
});
/**
* Create a new card
*/
router.post("/cards", async (req, res) => {
try {
const newCard = await db_1.db.insert(schema_1.tarotCards).values(req.body).returning();
res.status(201).json(newCard[0]);
}
catch (error) {
console.error("Error creating card:", error);
res.status(500).json({ message: "Internal server error" });
}
});
/**
* Bulk insert cards
*/
router.post("/cards/bulk", async (req, res) => {
try {
if (!Array.isArray(req.body)) {
return res
.status(400)
.json({ message: "Request body should be an array of cards" });
}
const newCards = await db_1.db.insert(schema_1.tarotCards).values(req.body).returning();
res.status(201).json(newCards);
}
catch (error) {
console.error("Error bulk inserting cards:", error);
res.status(500).json({ message: "Internal server error" });
}
});
/**
* Update a card by ID
*/
router.put("/cards/:id", async (req, res) => {
try {
const id = parseInt(req.params.id, 10);
const updatedCard = await db_1.db
.update(schema_1.tarotCards)
.set(req.body)
.where((0, drizzle_orm_1.eq)(schema_1.tarotCards.id, id))
.returning();
if (updatedCard.length === 0) {
res.status(404).json({ message: "Card not found" });
}
else {
res.json(updatedCard[0]);
}
}
catch (error) {
console.error("Error updating card:", error);
res.status(500).json({ message: "Internal server error" });
}
});
/**
* Delete a card by ID
*/
router.delete("/cards/:id", async (req, res) => {
try {
const id = parseInt(req.params.id, 10);
const deletedCard = await db_1.db
.delete(schema_1.tarotCards)
.where((0, drizzle_orm_1.eq)(schema_1.tarotCards.id, id))
.returning();
if (deletedCard.length === 0) {
res.status(404).json({ message: "Card not found" });
}
else {
res.json(deletedCard[0]);
}
}
catch (error) {
console.error("Error deleting card:", error);
res.status(500).json({ message: "Internal server error" });
}
});
exports.default = router;
26 changes: 26 additions & 0 deletions dist/src/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tarotCards = void 0;
const pg_core_1 = require("drizzle-orm/pg-core");
exports.tarotCards = (0, pg_core_1.pgTable)('thot_tarot', {
id: (0, pg_core_1.serial)('id').primaryKey(),
name: (0, pg_core_1.text)('name').notNull(),
number_meaning: (0, pg_core_1.text)('number_meaning').notNull(),
short_description: (0, pg_core_1.text)('short_description').notNull(),
long_description: (0, pg_core_1.text)('long_description'),
image_url: (0, pg_core_1.text)('image_url'),
ruling_planet: (0, pg_core_1.text)('ruling_planet'),
zodiac: (0, pg_core_1.text)('zodiac'),
tree_of_life: (0, pg_core_1.text)('tree_of_life'),
attributes: (0, pg_core_1.text)('attributes').array(),
element: (0, pg_core_1.text)('element'),
light_meanings: (0, pg_core_1.text)('light_meanings').array(),
shadow_meanings: (0, pg_core_1.text)('shadow_meanings').array(),
reversed_meaning: (0, pg_core_1.text)('reversed_meaning'),
advice: (0, pg_core_1.text)('advice'),
question: (0, pg_core_1.text)('question'),
confirmation: (0, pg_core_1.text)('confirmation'),
drive: (0, pg_core_1.text)('drive').array(),
keywords: (0, pg_core_1.text)('keywords').array(),
revelation: (0, pg_core_1.text)('revelation'),
});

0 comments on commit 75f2a78

Please sign in to comment.