-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: Create a dummy backend #79
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
Open
FabianGurevich
wants to merge
16
commits into
main
Choose a base branch
from
dummy-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fed662d
login endpoint without cookies
FabianGurevich e748c48
cookie in login
FabianGurevich 10344ac
add env in git ignore
FabianGurevich fc34384
remove .env development local
FabianGurevich 51e0f99
fix ci
FabianGurevich 3b1e0ae
fix linter
FabianGurevich 5302aec
update the package json
FabianGurevich 1b26c3b
exclude backend folder in the lint
FabianGurevich 6199e70
add readme
FabianGurevich e223f4f
changes readme
FabianGurevich 00f83b3
More changes in the readme
FabianGurevich 74e8ace
add status code
FabianGurevich 4cb7e10
Add how it works section
FabianGurevich d57296b
better name
FabianGurevich 00ec77c
PR feedback
FabianGurevich 70109f6
fix lint
FabianGurevich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
VITE_API_BASE_URL=REPLACE | ||
VITE_API_BASE_PATH=REPLACE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Dummy backend | ||
|
||
This backend is a lightweight, Express-based application designed to facilitate rapid testing of common workflows. It serves as a sandbox for developers to validate front-end integrations, prototype new features without relying on fully-fledged backend systems. | ||
|
||
## Setup | ||
|
||
In the backend-dummy folder run the following commands: | ||
|
||
1. Install the required packages: | ||
|
||
```shell | ||
npm install | ||
``` | ||
|
||
2. Starting the backend | ||
|
||
```shell | ||
npm start | ||
``` | ||
|
||
## How it works? | ||
|
||
This backend does not use a real database. However, there is a file named users.json that acts as a database. Refer to this file to see the available users for testing purposes. | ||
|
||
## Endpoints | ||
|
||
- [POST] users/login | ||
|
||
**Description** | ||
|
||
Validates the provided email and password. If successful, it sets a cookie with the user's session ID. | ||
|
||
**Responses** | ||
|
||
- **200 OK:** Login successful. The user's session cookie is set. | ||
- **400 Bad Request:** The request body is missing required fields (email or password). | ||
- **401 Unauthorized:** The provided email or password does not match any existing user. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var express = require("express"); | ||
var path = require("path"); | ||
var cookieParser = require("cookie-parser"); | ||
var logger = require("morgan"); | ||
|
||
var usersRouter = require("./routes/users"); | ||
|
||
var app = express(); | ||
|
||
app.use(logger("dev")); | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: false })); | ||
app.use(cookieParser()); | ||
app.use(express.static(path.join(__dirname, "public"))); | ||
|
||
app.use("/api/users", usersRouter); | ||
|
||
module.exports = app; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var app = require("../app"); | ||
var debug = require("debug")("backend-dummy:server"); | ||
var http = require("http"); | ||
|
||
/** | ||
* Get port from environment and store in Express. | ||
*/ | ||
|
||
var port = normalizePort(process.env.PORT || "3000"); | ||
app.set("port", port); | ||
|
||
/** | ||
* Create HTTP server. | ||
*/ | ||
|
||
var server = http.createServer(app); | ||
|
||
/** | ||
* 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) { | ||
var port = parseInt(val, 10); | ||
|
||
if (isNaN(port)) { | ||
// named pipe | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
// port number | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "error" event. | ||
*/ | ||
|
||
function onError(error) { | ||
if (error.syscall !== "listen") { | ||
throw error; | ||
} | ||
|
||
var bind = typeof port === "string" ? "Pipe " + port : "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() { | ||
var addr = server.address(); | ||
var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port; | ||
debug("Listening on " + bind); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.