generated from trywilco/Anythink-Market-Public
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
WilcoApp
committed
Jan 23, 2024
1 parent
19b3370
commit 25ce55d
Showing
175 changed files
with
6,621 additions
and
7,412 deletions.
There are no files selected for viewing
This file contains 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,42 +1,4 @@ | ||
{ | ||
"name": "Anythink Development Container", | ||
"image": "public.ecr.aws/v0a2l7y2/wilco/anythink-devcontainer:latest", | ||
"forwardPorts": [3000, 3001, 5433, 27017], | ||
"portsAttributes": { | ||
"3000": { | ||
"label": "Backend", | ||
"elevateIfNeeded": true, | ||
"requireLocalPort": true, | ||
"onAutoForward": "silent" | ||
}, | ||
"3001": { | ||
"label": "Frontend", | ||
"elevateIfNeeded": true, | ||
"requireLocalPort": true, | ||
"onAutoForward": "silent" | ||
}, | ||
"5433": { | ||
"label": "Database", | ||
"elevateIfNeeded": true, | ||
"requireLocalPort": true, | ||
"onAutoForward": "silent" | ||
}, | ||
"27017": { | ||
"label": "Database", | ||
"elevateIfNeeded": true, | ||
"requireLocalPort": true, | ||
"onAutoForward": "silent" | ||
} | ||
}, | ||
"postStartCommand": "bash -c .devcontainer/setup.sh", | ||
|
||
"settings": { | ||
"extensions.ignoreRecommendations": true, | ||
"workbench.startupEditor": "none", | ||
"workbench.colorTheme": "Visual Studio Dark", | ||
"workbench.colorCustomizations": {}, | ||
"workbench.welcomePage.walkthroughs.openOnInstall": false, | ||
"workbench.welcomePage.experimental.videoTutorials": "off", | ||
"github.codespaces.defaultExtensions": [] | ||
} | ||
"image": "public.ecr.aws/v0a2l7y2/wilco/anythink-devcontainer:latest" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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,26 +1,37 @@ | ||
.gradle/ | ||
/build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
*.db | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
|
||
### IntelliJ IDEA ### | ||
# Logs | ||
logs | ||
*.log | ||
.DS_Store | ||
|
||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
node_modules | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
nbproject/private/ | ||
build/ | ||
nbbuild/ | ||
dist/ | ||
nbdist/ | ||
.nb-gradle/ |
This file contains 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,2 +1 @@ | ||
FROM public.ecr.aws/v0a2l7y2/wilco/anythink-backend-java:latest | ||
|
||
FROM public.ecr.aws/v0a2l7y2/wilco/anythink-backend-node:latest |
This file contains 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,9 +1,10 @@ | ||
FROM openjdk:11 | ||
FROM node:16 | ||
|
||
WORKDIR /usr/src | ||
COPY backend ./backend | ||
COPY .wilco ./.wilco | ||
|
||
# Pre-install packages | ||
# Pre-install npm packages | ||
WORKDIR /usr/src/backend | ||
RUN ./gradlew build | ||
RUN yarn install | ||
|
This file was deleted.
Oops, something went wrong.
This file contains 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,35 +1,22 @@ | ||
# Anythink Market Backend | ||
|
||
# How it works | ||
The Anythink Market backend is Node web app written with [Express](https://expressjs.com/) | ||
|
||
The application uses Spring Boot (Web, Mybatis). | ||
## Dependencies | ||
|
||
And the code is organized as this: | ||
- [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) - For generating JWTs used by authentication | ||
- [mongoose](https://github.com/Automattic/mongoose) - For modeling and mapping MongoDB data to javascript | ||
- [mongoose-unique-validator](https://github.com/blakehaswell/mongoose-unique-validator) - For handling unique validation errors in Mongoose. Mongoose only handles validation at the document level, so a unique index across a collection will throw an exception at the driver level. The `mongoose-unique-validator` plugin helps us by formatting the error like a normal mongoose `ValidationError`. | ||
- [passport](https://github.com/jaredhanson/passport) - For handling user authentication | ||
- [slug](https://github.com/dodo/node-slug) - For encoding titles into a URL-friendly format | ||
|
||
1. `api` is the web layer implemented by Spring MVC | ||
2. `core` is the business model including entities and services | ||
3. `application` is the high-level services for querying the data transfer objects | ||
4. `infrastructure` contains all the implementation classes as the technique details | ||
## Application Structure | ||
|
||
# Getting started | ||
- `app.js` - The entry point to our application. This file defines our express server and connects it to MongoDB using mongoose. It also requires the routes and models we'll be using in the application. | ||
- `config/` - This folder contains configuration for passport as well as a central location for configuration/environment variables. | ||
- `routes/` - This folder contains the route definitions for our API. | ||
- `models/` - This folder contains the schema definitions for our Mongoose models. | ||
|
||
You'll need Java 11 installed. | ||
## Error Handling | ||
|
||
./gradlew bootRun | ||
|
||
To test that it works, open a browser tab at http://localhost:3000/api/tags | ||
Alternatively, you can run: | ||
|
||
curl http://localhost:3000/api/tags | ||
|
||
# Run test | ||
|
||
The repository contains a lot of test cases to cover both api test and repository test. | ||
|
||
./gradlew test | ||
|
||
# Code format | ||
|
||
Use spotless for code format. | ||
|
||
./gradlew spotlessJavaApply | ||
In `routes/api/index.js`, we define a error-handling middleware for handling Mongoose's `ValidationError`. This middleware will respond with a 422 status code and format the response to have [error messages the clients can understand](https://github.com/gothinkster/realworld/blob/master/API.md#errors-and-status-codes) |
This file contains 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,89 @@ | ||
require("dotenv").config(); | ||
var http = require("http"), | ||
path = require("path"), | ||
methods = require("methods"), | ||
express = require("express"), | ||
bodyParser = require("body-parser"), | ||
session = require("express-session"), | ||
cors = require("cors"), | ||
passport = require("passport"), | ||
errorhandler = require("errorhandler"), | ||
mongoose = require("mongoose"); | ||
|
||
var isProduction = process.env.NODE_ENV === "production"; | ||
|
||
// Create global app object | ||
var app = express(); | ||
|
||
app.use(cors()); | ||
|
||
// Normal express config defaults | ||
app.use(require("morgan")("dev")); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
|
||
app.use(require("method-override")()); | ||
app.use(express.static(__dirname + "/public")); | ||
|
||
app.use( | ||
session({ | ||
secret: "secret", | ||
cookie: { maxAge: 60000 }, | ||
resave: false, | ||
saveUninitialized: false | ||
}) | ||
); | ||
|
||
if (!isProduction) { | ||
app.use(errorhandler()); | ||
} | ||
|
||
if (!process.env.MONGODB_URI) { | ||
console.warn("Missing MONGODB_URI in env, please add it to your .env file"); | ||
} | ||
|
||
mongoose.connect(process.env.MONGODB_URI); | ||
if (isProduction) { | ||
} else { | ||
mongoose.set("debug", true); | ||
} | ||
|
||
require("./models/User"); | ||
require("./models/Item"); | ||
require("./models/Comment"); | ||
require("./config/passport"); | ||
|
||
app.use(require("./routes")); | ||
|
||
/// catch 404 and forward to error handler | ||
app.use(function (req, res, next) { | ||
if (req.url === "/favicon.ico") { | ||
res.writeHead(200, { "Content-Type": "image/x-icon" }); | ||
res.end(); | ||
} else { | ||
const err = new Error("Not Found"); | ||
err.status = 404; | ||
next(err); | ||
} | ||
}); | ||
|
||
/// error handler | ||
app.use(function(err, req, res, next) { | ||
console.log(err.stack); | ||
if (isProduction) { | ||
res.sendStatus(err.status || 500) | ||
} else { | ||
res.status(err.status || 500); | ||
res.json({ | ||
errors: { | ||
message: err.message, | ||
error: err | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
// finally, let's start our server... | ||
var server = app.listen(process.env.PORT || 3000, function() { | ||
console.log("Listening on port " + server.address().port); | ||
}); |
Oops, something went wrong.