ferg1e / comment-castles

Lightweight internet forum
https://www.commentcastles.org
MIT License
63 stars 6 forks source link

Split up source code into smaller files #8

Open ferg1e opened 3 years ago

ferg1e commented 3 years ago

All the website routes are in routes/active.js and all the SQL queries are in db/index.js. These two files should be split up into smaller files - possibly grouping things into files (as opposed to using a single file for each function).

ferg1e commented 3 years ago

The routes have been split up. We still need to do the SQL.

OmgImAlexis commented 2 years ago

Can I take this task?

ferg1e commented 2 years ago

Of course. What's your plan? As you can see from the comments here I already did it to the routes. Would you be doing the SQL? I just wonder what the db imports will look like when done - right now we just include the whole thing on any route that needs to make at least one db call. I have the db calls grouped (there's a comment at the top of each grouping).

Also, I have made some style edits to the refactor that you did, and I will push them soon. You may want to wait and see that.

OmgImAlexis commented 2 years ago

Do you have a discord where we could chat about this?

I plan on moving all the functions from the misc to their own files in a new directory called common. Each function will have comments and jsdoc style types.

The SQL I'll move to using https://www.npmjs.com/package/sql-template-strings as it helps a lot with making the queries easier to read. I'll also move the queries to their own files in a directory called queries which can then be imported where needed.

In terms of the routes they need to be split up too as they're handling more than the route. They're also rendering error pages for some reason. For example https://github.com/ferg1e/peaches-n-stink/blob/3d4eeee646b159c3f38840170ee6a8f81742f2dc/routes/display-single-post.js#L94-L120 these lines should all be removed and instead error middleware should be added. Same goes for moving things like max_width: myMisc.getCurrSiteMaxWidth(req), to a local that's injected by middleware right at the start of the app instead of relying on the route to pass it though to the locals.

To help with this I'd also suggest moving to https://www.npmjs.com/package/express-promise-router

ferg1e commented 2 years ago

I created a discord:

https://discord.gg/Uwp2Ya8843

Pop by if you get a chance.