-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Upgrade to TypeScript, add data types, and mock auth #39
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
Changes from 3 commits
62fb7ed
f0c5450
7730fa9
2b9822f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| node_modules | ||
| node_modules | ||
|
|
||
| # Vitest coverage directory | ||
| coverage/ |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const express_1 = __importDefault(require("express")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const path_1 = __importDefault(require("path")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const cookie_parser_1 = __importDefault(require("cookie-parser")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const morgan_1 = __importDefault(require("morgan")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const cors_1 = __importDefault(require("cors")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const index_1 = __importDefault(require("./routes/index")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const users_1 = __importDefault(require("./routes/users")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const posts_1 = __importDefault(require("./routes/posts")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const postwithuser_1 = __importDefault(require("./routes/postwithuser")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const products_1 = __importDefault(require("./routes/products")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const restaurants_1 = __importDefault(require("./routes/restaurants")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const auth_1 = __importDefault(require("./routes/auth")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const companies_1 = __importDefault(require("./routes/companies")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const addresses_1 = __importDefault(require("./routes/addresses")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const orders_1 = __importDefault(require("./routes/orders")); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const app = (0, express_1.default)(); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| app.use((0, morgan_1.default)('dev')); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| app.use(express_1.default.json()); | ||
| app.use(express_1.default.urlencoded({ extended: false })); | ||
| app.use((0, cookie_parser_1.default)()); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| app.use(express_1.default.static(path_1.default.join(__dirname, '..', 'public'))); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| app.use((0, cors_1.default)()); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| app.use('/', index_1.default); | ||
| app.use('/users', users_1.default); | ||
| app.use('/posts', posts_1.default); | ||
| app.use('/postwithuser', postwithuser_1.default); | ||
| app.use('/products', products_1.default); | ||
| app.use('/restaurants', restaurants_1.default); | ||
| app.use('/auth', auth_1.default); | ||
| app.use('/companies', companies_1.default); | ||
| app.use('/addresses', addresses_1.default); | ||
| app.use('/orders', orders_1.default); | ||
| // Error handling middleware (optional, but good practice) | ||
| app.use((err, req, res, next) => { | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| console.error(err.stack); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| res.status(500).send('Something broke!'); | ||
| }); | ||
| exports.default = app; | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env node | ||
| "use strict"; | ||
| /** | ||
| * Module dependencies. | ||
| */ | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const app_1 = __importDefault(require("../app")); // Will resolve to app.ts | ||
|
||
| const debug_1 = __importDefault(require("debug")); | ||
|
||
| const http_1 = __importDefault(require("http")); | ||
|
||
| const debug = (0, debug_1.default)('mock-api:server'); | ||
|
||
| /** | ||
| * Get port from environment and store in Express. | ||
| */ | ||
| const port = normalizePort(process.env.PORT || '3006'); | ||
|
||
| app_1.default.set('port', port); | ||
| /** | ||
| * Create HTTP server. | ||
| */ | ||
| const server = http_1.default.createServer(app_1.default); | ||
|
||
| /** | ||
| * Listen on provided port, on all network interfaces. | ||
| */ | ||
| server.listen(port); | ||
| server.on('error', onError); | ||
| server.on('listening', onListening); | ||
| /** | ||
| * Normalize a port into a number, string, or false. | ||
| */ | ||
| function normalizePort(val) { | ||
| const portNumber = parseInt(val, 10); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (isNaN(portNumber)) { | ||
| // named pipe | ||
| return val; | ||
| } | ||
| if (portNumber >= 0) { | ||
| // port number | ||
| return portNumber; | ||
| } | ||
| return false; | ||
| } | ||
| /** | ||
| * Event listener for HTTP server "error" event. | ||
| */ | ||
| function onError(error) { | ||
| if (error.syscall !== 'listen') { | ||
| throw error; | ||
| } | ||
| const bind = typeof port === 'string' | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ? 'Pipe ' + port | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| : 'Port ' + port; | ||
| // handle specific listen errors with friendly messages | ||
| switch (error.code) { | ||
| case 'EACCES': | ||
| console.error(bind + ' requires elevated privileges'); | ||
| process.exit(1); | ||
| break; | ||
| case 'EADDRINUSE': | ||
| console.error(bind + ' is already in use'); | ||
| process.exit(1); | ||
| break; | ||
| default: | ||
| throw error; | ||
| } | ||
| } | ||
| /** | ||
| * Event listener for HTTP server "listening" event. | ||
| */ | ||
| function onListening() { | ||
| const addr = server.address(); | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let bind; | ||
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
StanleyMasinde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (typeof addr === 'string') { | ||
| bind = 'pipe ' + addr; | ||
| } | ||
| else if (addr) { | ||
| bind = 'port ' + addr.port; | ||
| } | ||
| else { | ||
| bind = 'an unknown address'; // Should not happen in normal circumstances | ||
| } | ||
| debug('Listening on ' + bind); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| [ | ||
| { | ||
| "id": "fa94e061-5cfd-4712-8df5-7c7ada3599b5", | ||
| "street": "6928 E 1st Street", | ||
| "city": "Sugar Land", | ||
| "zipCode": "50990", | ||
| "country": "Belgium", | ||
| "userId": "4" | ||
| }, | ||
| { | ||
| "id": "2f815f6e-6ed4-405b-87f1-ed8ffbfdff2c", | ||
| "street": "74021 West Avenue", | ||
| "city": "Baileycester", | ||
| "zipCode": "50210", | ||
| "country": "Guinea" | ||
| }, | ||
| { | ||
| "id": "a701d0bc-a520-4275-a6a4-723c126709be", | ||
| "street": "2497 Manor Drive", | ||
| "city": "Juwanbury", | ||
| "zipCode": "96278-8054", | ||
| "country": "Fiji", | ||
| "userId": "1" | ||
| }, | ||
| { | ||
| "id": "8ea3941a-2aa9-4380-b4e9-391ef24e2e05", | ||
| "street": "749 Grove Lane", | ||
| "city": "Greenfelderbury", | ||
| "zipCode": "26177-0813", | ||
| "country": "Gambia" | ||
| }, | ||
| { | ||
| "id": "3feab1dd-7009-4888-a2a3-af2de3b9df09", | ||
| "street": "5218 Jefferson Street", | ||
| "city": "Quintonshire", | ||
| "zipCode": "82871", | ||
| "country": "Lithuania", | ||
| "userId": "1" | ||
| }, | ||
| { | ||
| "id": "92ebb772-7f51-452e-8394-4ad2542896b5", | ||
| "street": "501 Fahey Street", | ||
| "city": "East Jermainmouth", | ||
| "zipCode": "16273-2342", | ||
| "country": "Togo" | ||
| }, | ||
| { | ||
| "id": "8306a3b0-1b5d-42ed-b98f-b4648657cac7", | ||
| "street": "363 E Main Street", | ||
| "city": "West Randi", | ||
| "zipCode": "09860", | ||
| "country": "Northern Mariana Islands" | ||
| }, | ||
| { | ||
| "id": "5ccad40d-24e1-4688-b049-a709d1fcef60", | ||
| "street": "29721 Water Lane", | ||
| "city": "East Joanie", | ||
| "zipCode": "31498-1740", | ||
| "country": "Australia" | ||
| }, | ||
| { | ||
| "id": "da8999bd-c7ca-48d9-861e-265fcacec718", | ||
| "street": "859 Willms Vista", | ||
| "city": "Monroefort", | ||
| "zipCode": "47973-0287", | ||
| "country": "Lesotho" | ||
| }, | ||
| { | ||
| "id": "d84ec28f-a53c-4129-9ba0-a913853bc41f", | ||
| "street": "807 Wolf Island", | ||
| "city": "North Salvatorechester", | ||
| "zipCode": "01345-2723", | ||
| "country": "Lebanon", | ||
| "userId": "2" | ||
| }, | ||
| { | ||
| "id": "417c5a5c-a26d-4106-8d37-f8e706cb3d9a", | ||
| "street": "536 Kuhic Harbor", | ||
| "city": "Keeblerchester", | ||
| "zipCode": "78647", | ||
| "country": "Namibia", | ||
| "userId": "1" | ||
| }, | ||
| { | ||
| "id": "e8ceda23-21db-4b39-ad96-09d10f4c26ed", | ||
| "street": "131 E Main", | ||
| "city": "Audreanneberg", | ||
| "zipCode": "69765", | ||
| "country": "Sweden" | ||
| }, | ||
| { | ||
| "id": "70b947d9-60b0-4f49-a641-b3e07d9db702", | ||
| "street": "55695 Jerod Spring", | ||
| "city": "Mooremouth", | ||
| "zipCode": "32290", | ||
| "country": "Azerbaijan" | ||
| }, | ||
| { | ||
| "id": "1381a987-966c-4679-a2bf-4798929c3610", | ||
| "street": "180 N Broadway", | ||
| "city": "Fort Ethyl", | ||
| "zipCode": "17089-0826", | ||
| "country": "Seychelles" | ||
| }, | ||
| { | ||
| "id": "35abd1b2-91f5-4561-903e-a3efd5f8065c", | ||
| "street": "9967 Fay Landing", | ||
| "city": "Port Ednaside", | ||
| "zipCode": "84893-3585", | ||
| "country": "Luxembourg" | ||
| }, | ||
| { | ||
| "id": "ee1f6507-5404-4e62-ac13-1b9f0675c996", | ||
| "street": "9799 Ebert Circle", | ||
| "city": "Katlynnberg", | ||
| "zipCode": "16995", | ||
| "country": "Fiji" | ||
| }, | ||
| { | ||
| "id": "52c86a43-0afa-4e44-9011-ff132d51c32d", | ||
| "street": "99370 Ola Trace", | ||
| "city": "Melodystead", | ||
| "zipCode": "57916-5940", | ||
| "country": "North Macedonia", | ||
| "userId": "3" | ||
| }, | ||
| { | ||
| "id": "23a3cb06-1ca0-4548-bc7a-95ae7f21a64c", | ||
| "street": "5286 Schneider Summit", | ||
| "city": "South Braulio", | ||
| "zipCode": "99944", | ||
| "country": "Panama", | ||
| "userId": "2" | ||
| }, | ||
| { | ||
| "id": "a043d916-4eff-4d66-8810-61e09c2b31c0", | ||
| "street": "88796 Jessyca Field", | ||
| "city": "Farmington Hills", | ||
| "zipCode": "90269", | ||
| "country": "Vietnam", | ||
| "userId": "1" | ||
| }, | ||
| { | ||
| "id": "0f244bb7-bcef-4c77-85dc-a550c4d064cb", | ||
| "street": "520 Amalia Glen", | ||
| "city": "South Abbeyborough", | ||
| "zipCode": "08120", | ||
| "country": "South Africa", | ||
| "userId": "1" | ||
| } | ||
| ] |
Uh oh!
There was an error while loading. Please reload this page.