{"id":22559671,"url":"https://github.com/taurusilver7/fresh-pages-server","last_synced_at":"2025-08-18T10:04:45.757Z","repository":{"id":181445538,"uuid":"360106881","full_name":"taurusilver7/fresh-pages-server","owner":"taurusilver7","description":"The server-side for the web app. API for the application.","archived":false,"fork":false,"pushed_at":"2024-03-01T12:08:56.000Z","size":173,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T12:12:05.404Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://fresh-pages.onrender.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/taurusilver7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-21T09:20:57.000Z","updated_at":"2024-04-22T12:07:51.000Z","dependencies_parsed_at":"2025-02-02T12:34:41.107Z","dependency_job_id":"1dcb3c20-616c-4412-beae-617115630183","html_url":"https://github.com/taurusilver7/fresh-pages-server","commit_stats":null,"previous_names":["taurusilver7/fresh-pages-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/taurusilver7/fresh-pages-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taurusilver7%2Ffresh-pages-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taurusilver7%2Ffresh-pages-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taurusilver7%2Ffresh-pages-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taurusilver7%2Ffresh-pages-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taurusilver7","download_url":"https://codeload.github.com/taurusilver7/fresh-pages-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taurusilver7%2Ffresh-pages-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270975286,"owners_count":24678274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-07T21:07:55.957Z","updated_at":"2025-08-18T10:04:45.733Z","avatar_url":"https://github.com/taurusilver7.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fresh Pages\n\n\u003e A Fully Server-Side Writing Platform\n\n\u003e A MERN CRUD Application API \u0026 Client.\n\u003e A fully server-side function for the story book application.\n\u003e MVC architecture in API building.\n\n![fresh-pages](https://i.ibb.co/SxLMzBM/fresh-pages.png)\n\n### Setup work environment.\n\nStart the application in a local development server.\n\n```bash\nnpm init -y\n# and\nnpm run dev\n```\n\n-  The application modes are set in the _package.json_ for test, development \u0026 production modes.\n   \u003cbr /\u003e\n-  import the required dependencies \u0026 dev-dependencies with `npm install \u003cpackage\u003e` \u0026 `npm install \u003cpackage\u003e --save-dev`.\n   \u003cbr /\u003e\n-  set up the required scripts for development \u0026 production modes.\n\n---\n\nSet up the server with application configuration, env config, template-engine, application listeners.\nSetup a db in _./config/_ for the database configuration \u0026 connect it to the server.\nCreate views directory for template literals \u0026 organise directory layout.\nCreate routes directory for api routes \u0026 create routes for top-level routes [dashboard, login/landing] in **index.js**.\n\n---\n\n-  Use [materialize](https://materializecss.com/getting-started.html) to add design to the webpage.\n-  Use [font-awesome](https://cdnjs.com/libraries/font-awesome) to add stylish fonts to the webpages in api.\n\n---\n\n-  create a public directory to hold all the static files for the application [css, imgs, icons] \u0026 configure it to the server file to recognize the static directory.\n-  Render the routes in /routes with corresponding **.hbs** files in _/views_.\n\n---\n\n### Authenticate Application\n\n-  create a project for the application in google-cloud-console \u0026 enable api services for the application. add a redirect url to working localhost now \u0026 hosted homepage in future to enable google oauth services.\n-  ---\u003e Copy the **client id \u0026 client secret** for enabling the google+ services\n\n---\n\n-  create a _googleStrategy_ using passport js for 2 specified login routes for the api.\n-  create passport strategy using google strategy for success \u0026 error routes \u0026 re-directs.\n-  The passport configuration is created in _/config_ dir \u0026 imported to server.\n-  create passport middleware with **initialize \u0026 session** from passport [passport-session only works with express sessions initialized above]\n\n---\n\n### Mongoose models\n\n-  a _/models_ directory to hold the db models using mongoose is created to store the models in passport strategy.\n-  A mongoose model with a schema to get the user info is created in _/models/User.js_\n\n\u003e In a typical web application, the credentials used to authenticate a user will only be transmitted during the login request. If authentication succeeds, a session will be established and maintained via a cookie set in the user's browser.\n\u003e Each subsequent request will not contain credentials, but rather the unique cookie that identifies the session. In order to support login sessions, Passport will serialize and deserialize user instances to and from the session.\n\n-  The passport strategy allows the user to login with google+ authentication using passport-js\n-  The login \u0026 logout routes are created in _/routes/auth.js_.\n-  A partial view template to insert into other template (main.hbs) to get a navbar for logout button.\n-  A script for the side navbar operation is created at **main.hbs**\n\n---\n\n-  to avoid a user/non-user/guest to redirect to other pages through url's, a middleware to authorize the user/guest priviliages is created in _/controller/auth.js_.\n-  The user/ guest priviliges are tightly bound. But the user session expires with every refresh/ app changes. To avoid this, the session is stored in database with **mongo-connect** package\n-  The package used for session storing is `connect-mongo@3` with `express-session`. The store location is the current mongoose.connection.\n\n---\n\n### Create Stories for the App\n\n-  create a model for the story in the user dashboard.\n-  In the index routes, for the dashboard, restrict the find to _user.id_ from the req \u0026 enable `lean()` to make the document returned from queries as plain js objects but not mongoose documents.\n\n-  create a 404 error \u0026 500 internal server error templates for error rendering in the dashboard route.\n-  The dashboard table for stories is created in /dashboard.hbs\n-  Add a stroy add button in partials \u0026 add it to the main template.\n-  Create a _/stories_ dir in views to create different types of templates for creating, editing stories. Add their corresponding routes to the _/router_.\n-  Link the stories route to the server. Add the script for status selection in **add.hbs** template to the **main.hbs**\n\n---\n\n-  For the textarea in the /stories/add route to be converted into `wysiwyg editor`, **ck editor** is imported as script.\n-  more about wysiwyg editor is [here](https://froala.com/wysiwyg-editor/)\n-  cdn for ck editor v4.16.0 is [here](https://cdnjs.com/libraries/ckeditor)\n\n-  To post the data to database, a post req is created in /stories route with body-parsers enabled in server, for webpage rendering.\n-  format the date in each story in the dashboard, using a helper to wrap around date to format it. Register the helper with handlebars in server to use it in templates\n-  The moment format required (used) in app is 'MMMM Do YYYY, h:mm:ss a'\n\n---\n\n### Adding \u0026 Editing Stories\n\n-  create a public stories end point to the api. create a template in _/stories/index.hb_s for the get route in _/routes/stories\\_.\n-  To refactor the webpage, some helpers to strip the p-tags, truncate the text are created.\n-  Register the helper functions in server to use them in templates.\n\n---\n\n-  A helper function editIcon to intiate a story editing is created along with the template for the edit button.\n-  create a route for editing \u0026 template for the edit web-page \u003e\u003e _/stories/edit.hbs_ \u0026 _/routes/stories_\n-  The edit tempate is similar to add template with already values of the story ready to be edited \u003e\u003e `value=\"{{story.title}}\"` \u003e\u003e `\u003ctextarea\u003e{{story.body}}\u003c/textarea\u003e`\n-  To edit the story status in the database, they are wrapped in a select helper function \u003e\u003e\n   `{{#select story.status}}` with their status as selectors.\n\n-  the edit function is a PUT request, which simply cannot be added to form\u003emethod. The **method-override** package is imported to add a hidden input(desired method=PUT/PATCH/DEL) to the html form(default method=POST) as a middleware.\n   `\u003cinput type=\"hidden\" name=\"_method\" value=\"\"PUT\"\u003e`\n\n---\n\n-  create a button that uses method-override to delete a story from the dashboard.\n-  create a delete req in /routes/stories with method _model.remove()_\n\n-  create a get request for single story \u0026 create a template for it. \u003e\u003e _/stories/show.hbs_\n-  create a get request for user stories only \u0026 template used for web-page is _/stories/index.hbs_\n\n# Deployment\n\nDeploy the server application on [render](https://render.com) with custom parameters and settings.\n\nCheck the deployed [fresh-pages](http://fresh-pages.onrender.com/) here and create your own stories.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaurusilver7%2Ffresh-pages-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaurusilver7%2Ffresh-pages-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaurusilver7%2Ffresh-pages-server/lists"}