Skip to content

imKashyap/Standalone-Server

Repository files navigation

Standalone-Server

CI License: MIT Documentation Status

  • Standalone Server is a web server built using Shelf in dart.
  • A sample project with an entrypoint in bin/, library code in lib/, client side code in public/, and example unit test in test/.
  • The server serves some static HTML files (including CSS ) & a PDF file. I have implemented user authentication using JWT tokens. Only once the user gets authenticated, He/She can view the PDF or Edit Name.
  • To handle authentication on client-side, I have used cookies to store tokens. This ensures flawless and secured frontend-backend communication.

Demo Video


Table of Contents


Features

Following features have been implemented:

  • ✅ Serve REST requests (GET, POST, PATCH, DELETE)
  • ✅ Serve static files from the server to authenticated users only
  • ✅ Render HTML templates
  • ✅ Convert Dart to JS for use client-side using dart2js compiler
  • ✅ Authenticate users using JWT Token
  • ✅ Local JSON Database under database/users.json

Screenshots

Screen Name Screenshots
Landing Page Screenshot of the App
Login Page Screenshot of the App
Register Page Screenshot of the App
Dashboard Page Screenshot of the App

Code Structure

standalone_server
 ┃
 ┣ bin (contains main server.dart file )
 ┃
 ┣ database (contains a user.json file storing users list as  local JSON storage)
 ┃
 ┣ lib
 ┃ ┣ interops (contains dart codes for Javascript interoperability)
 ┃ ┣ src
 ┃ ┃ ┣ apis
 ┃ ┃ ┃ ┗ validators (validator for validating input fields like name, email & password)
 ┃ ┃ ┣ configs
 ┃ ┃ ┃ ┣ routes.dart (all the routes mounted)
 ┃ ┃ ┃ ┗ utils.dart (functions commonly used are mentioned here)
 ┃ ┃ ┗ models (contains user model)
 ┃ ┗ server.dart (exports the package to bin/server.dart)
 ┃
 ┣ public (contains client side code like css, html & assets)
 ┃ ┗ assets
 ┃
 ┣ resources (contains screenshots & demo video)
 ┃
 ┗test (contains test.dart file)

API Docs

Routes REST request Description Requirements
/ GET serves landing.html page
/auth/register GET serves register.html page
/auth/register POST registers the user and returns a JWT token needs name, email & password as body
/auth/login GET serves login.html page
/auth/login POST logs in the user and returns a JWT token needs email & password as body
/assets/<file.*> GET serves static files under public/assets/
/auth/logout POST logs out the user needs Bearer token as authorization header
/user/ GET returns logged in user info in JSON needs Bearer token as authorization header
/user/ PATCH edits the name of logged in user needs Bearer token as authorization header & new name as body
/user/ DELETE deletes logged in user account needs Bearer token as authorization header
/dashboard GET serves dashboard.html page
/file/<userid>/<file.*> GET serves files from disk to authenticated users only (Here, sample.pdf)

Getting Started

Perform the following operations to set up the project.

git clone git@github.com:imKashyap/Standalone-Server.git
pub get
nodemon

Nodemon is an NPM package used to watch for the changes in source code and restart the shelf server automatically. You can install it by doing npm i -g nodemon. But make sure node is installed in your machine.

Visit http://localhost:4040 and make sure you see the following screen:

Screenshot of the landing page of Web Server

License

MIT

About

A Standalone Server in Dart and frontend in HTML & CSS. This is a sample GSoC 2021 Project under dart organization.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published