drashland / deno-drash-realworld-example-app Goto Github PK
View Code? Open in Web Editor NEWDeno + Drash RealWorld example app
License: MIT License
Deno + Drash RealWorld example app
License: MIT License
Add stress testing to the realworld example app.
Why?
This repo represents a realworld example application, adding stress testing better 'enforces' this - it can be used to show people how a realworld app would perform.
How?
docker run
instead as it might be simplerwrk
(npm, https://github.com/wg/wrk)autocannon
(https://github.com/mcollina/autocannon)docker-compose.yml
file that we can specify using docker-compose up -d -docker-compose.yml -f docker-compose.stress.yml
docker-compose.yml
file but relies on an environmental variable (eg test
maybe?)docker run
as a one-off to run the tests. I don't have much experience with this so I cannot provide more details but it might prove more useful than the points aboveChecklist
Resources
Links are attached for tools to be used for this feature above, but using Drash's benchmark examples can also be useful
Relies on #8 to be completed
Develop tests for the home resource. Tests are being developed late as it is unclear what the requirements are yet
Go to the New Article page and try to add tags by entering some text and pressing enter
Currently, the errors on the front-end don't show up if errors are received from the server. we need to handle them using a modal or message at the top of the page. Either way we handle it, we need to show the errors to the user so they know what exactly is going wrong when they take steps throughout the application.
Overview
Specs as specified from realworld:
- Sign in/Sign up pages (URL: /#/login, /#/register )
* Uses JWT (store the token in localStorage)
* Authentication can be easily switched to session/cookie based
There a few questions I have around this as to how it's implemented (and why it mentions the register resource)
All API calls would need to pass in the token (unless it is automatically passed) and the API would need to authenticate all requests using this
Currently we have docblocks that have curly brackets and others that don't. Let's choose one standard and go with it.
/#/login should hit /login endpoint
/#/register should hit /users/create endpoint
What: If you run deno lint
, we will most likely have a whole bunch of errors. This issue to fix these errors by correctly formatting code, and abiding by Deno's standards
Why: It would be good to make sure the code follows either: Deno's best practices, coding standards, or general best practices. It's a Deno project so it makes sense to utilise their tools on making the code Deno-like
deno lint
is added to the master.yml
CI, as a new block (similar to how we use deno fmt --check
on some repositories)deno lint
produces no errorsWhat:
Don't allow duplicate articles to be posted. To address this, we'd need to generate a random string (std uuid) as the slug instead for each article, then that would become the slug, OR use the rows database ID as it's identifier, eg /article/2
. See screenshot below for more context.
Why:
The app will go into a meltdown if there are multiple articles saved with the same name, because the slug is the name, and we fetch based on the slug... in a nutshell, the app could get a wrong article
If you take on this issue and the acceptance criteria does not make sense, post comments on this issue with your questions. Also, you can always hop in the Discord channel at https://discord.gg/c5R3sYuR to get help quickly.
Please read the Contributing Guidelines before starting this issue.
Overview
Specs as specified from realworld:
- Editor page to create/edit articles (URL: /#/editor, /#/editor/article-slug-here )
Requirements
/article
routes
Optional
Related Files
/src/resources/api_editor_resource.ts
or /src/api/resources/editor_resource.ts
/src/vue/?
example code:
beforeRouteEnter(to, from, next) {
next((vm => {
vm.username = "";
vm.email = "";
vm.password = "";
});
}
Describe the bug
On creating an article with no body, the body displays as "undefined" in the UI. And upon creating a new article, the fields are still set, and they also show as "undefined"
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I should not be allowed to do this
Suggested Solution(s)
Validate the data on the backend, if any of the fields are empty then the user shouldnt be allowed to create the article
It'd be useful if we can install the npm dependencies and build webpack when the container starts (docker-compose up
). This logic could be in an entrypoint script or it could be added to the command
line in the drash block of docker-compose.yml
Pseudo Code
// .docker/drash.dockerfile
RUN apt update -y \
&& apt install -y --no-install-recommends nodejs npm
RUN npm install -g npm@latest
What: Credit and show which tools we used to help build this application, for example, bcrypt and postgres
Why: It would give a better insight into how this was built, and give credit to the authors to show their projects helped the realworld app. I guess this is mainly centered around Deno modules we are using (see deps.ts)
3rd party tools used:
* [bcrypt](github.com/james/bcrypt) - Aid in the authentication for users, to hash and compare passwords
* [postgres](...) - Postgres driver to allow us to connect to a postgres database, and run queries
Question: See point 4 in Requirements
Overview
Rework the existing home page to adhere to the following requirements.
Specs as specified from realworld:
- Home page (URL: /#/ )
* List of tags
* List of articles pulled from either Feed, Global, or by Tag
* Pagination for list of articles
Requirements
Optional
Related Files
/src/resources/home_resource.ts
/src/vue/?
/src/public/?
Improve upon the home resource and view, to make a proper home page. Not entirely sure what it should be but i reckon, maybe just display the list of all users in the system
Related Files
Looking for feedback from @crookse and @Guergeiro
Should we seperate the API logic & files from the main server?
Eg we could have a file structure like:
/.docker/
src/
api/
resources/
article_resource.ts
...
server|client/
resources/
home_resource.ts
..
This would help in understand the resources, as we might have to have the api resources named like api_article_resource.ts
and also make the file structrue more readable maybe? Curious what you guys think
Overview
Specs as specified from realworld:
- Profile page (URL: /#/profile/:username, /#/profile/:username/favorites )
* Show basic user info
* List of articles populated from author's created articles or author's favorited articles
Requirements
/profile/:username
routes
profiles
so that it returns the following model:
{
"username": "jake",
"bio": "I work at statefarm",
"image": "https://static.productionready.io/images/smiley-cyrus.jpg",
"following": false
}
Optional
Related Files
/.docker/data/postgres_dump.sql
/src/resources/profiles_resource.ts
/src/vue/routes/Profile.vue
Add to /src/databases/realworld.db
to create a Users table and populate it with example data, for example, maybe 20+ users.
Gives us some database data to work with
Create about 100 users in the database so we have a good amount of data to work with, then make sure the data is dumped to overwrite the current dump file in /.docker/data/
Question: See point 1.4 of Requirements
Overview
Specs as specified from realworld:
- Settings page (URL: /#/settings )
Requirements
/settings
routes
Optional
Related Files
/src/resources/api_settings_resource.ts
or /src/api/resources/settings_resource.ts
/src/vue/?
The "Notes" section in the README.md were purely for helping myself and other developers with working in this environment whilst in development (eg so i dont forget how to login into the postgres container).
Move those markdown blocks into a DEV.md
file, as it shouldn't be in the README anyways
The DEV.md
file needs to be created as it doesn't currently exist
When returning a User or Profile object, make sure the raw password is not sent in the response.
test
Includes:
Related Files
What: Convert JSDoc blocks (though we use a mix of JSDoc and Deno's standard), to TSDoc blocks in Typescript files
Why: We primarily use TypeScript so it makes sense to use TSDoc. Types are already documented in the method/property anyways.
* @param string filename
* The filename to do something with
* @param filename - The filename to do something with
TSDoc is very similar, there is really only a few minor changes to make to each doc block
Review missing doc blocks that are missing on all methods in the backend code - If a method doesn’t have one then create one
These weren’t created from the start as the app was very early in the build stage but everything is starting to become more concrete
Currently, Apache serves no purpose, which makes me feel we may as well remove it.
But i'm curious if it might be used further down the line? If so we may as well leave it in as it is already setup - plus it serves as documentation on apache (proxy) + docker + drash
Develop route tests for the register resource. Tests are being developed late as it is unclear what the requirements are yet
Has to be tested from within the docker container
GET request
POST request
What: Vue doesn't handle the removal of tags when creating an article:
Add this functionality
Why: It's part of the specs and requirements
setTags
but without the passed in tag// Add example pseudo code for implementation
Develop the logic to delete a comment for an article, when they click the 'trash' button
When accessing /articles/:slug
when not logged in, and the article doesn't exist, the page still displays and there's a bunch of JS errors eg the client isn't handling the errors properly.
This issue is to address this, so the user gets a redirect to login
Develop all logic for registering a user
Related Files
Allow a models database queries to be updated with dynamic data, for example in PHP using PDO:
const INSERT = "INSERT INTO table (...) VALUES (?, ?, ?)"
Then possibly have a method to go through this query and update it with passed in data? Or is there a better approach?
Currently, the postgres plugin doesn't sanitize inputs. We should add logic to sanitize our inputs before they're entered into the database. We have some good validation as a starting point in the user_model.ts
file. We should expand on our validation efforts.
You can test this by following the steps below:
' WHERE id = '1'; UPDATE users SET username = 'test
Notice that you're username becomes test.
Relies on #3 to be completed
Develop tests for the login resource. Tests are being developed late as it is unclear what the requirements are yet
When using localhost:8080
, we get the below errors when sending a POST
to /login
and /register
@Guergeiro Also mentioned we get CORs problems when using 127.0.0.1:*
Figure out a solution to this to fix the errors.
Errors (in console)
Access to XMLHttpRequest at 'http://localhost:1667/users' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
actions.js:118 Registration unsuccessful.
xhr.js:175 POST http://localhost:1667/users net::ERR_FAILED
dispatchXhrRequest @ xhr.js:175
xhrAdapter @ xhr.js:18
dispatchRequest @ dispatchRequest.js:40
Promise.then (async)
request @ Axios.js:64
Axios.<computed> @ Axios.js:88
wrap @ bind.js:11
eval @ actions.js:108
register @ actions.js:107
wrappedActionHandler @ vuex.esm.js:840
dispatch @ vuex.esm.js:478
boundDispatch @ vuex.esm.js:361
eval @ Register.vue?./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-
loader-options:73
Promise.then (async)
onSubmit @ Register.vue?./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??
vue-loader-options:72
submit @ Register.vue?./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-
options!./node_modules/vue-loader/lib??vue-loader-options:44
invokeWithErrorHandling @ vue.js:1888
invoker @ vue.js:2219
original._wrapper @ vue.js:7510
actions.js:119 Uncaught (in promise) TypeError: Cannot read property 'data' of undefined
at eval (actions.js:119)
This is depended on by #42.
More enforces a realworld app.
This should check if the user is authed (yet to be implemented how of this works). If not then redirects to login resource
Related Files
Question: See point 4 in Requirements
Overview
Specs as specified from realworld:
- Article page (URL: /#/article/article-slug-here )
* Delete article button (only shown to article's author)
* Render markdown from server client side
* Comments section at bottom of page
* Delete comment button (only shown to comment's author)
Requirements
/api/article
routes
articles
. Structure is currently unknown and needs to be investigatedOptional
Related Files
/.docker/data/postgres_dump.sql
/src/resources/api_article_resource.ts
or /src/api/resources/article_resource.ts
/src/vue/?
Relies on #3 and #4 to be completed
What:
Add logic for hashing passwords when registering a user account (most likely would reside in the user model?)
Update all existing users in the db to have hashed passwords
Add logic for logging in, to compare requested password with the db password matching requested email
Resources:
Found a module that we can use! https://github.com/JamesBroadberry/deno-bcrypt
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.