Skip to content

A Node.js server application that powers the eodiro.com

License

Notifications You must be signed in to change notification settings

payw-org/eodiro-server

Repository files navigation

eodiro 🌏 server

A Node.js server application that powers the eodiro

npm npm


πŸ“¦ Spec

Node.js running on NGINX using reverse proxy.

NGINX

SSL: Let's Encrypt and Certbot python plugin

Configuration

Resolve 413 Request Entity Too Large

server {
    client_max_body_size 3M;
}

Don't forget

  • to set timezone correctly of both system and database

Database

It uses MySQL internally as its database.

Installation


πŸ“š API References

REST

One API (deprecated)


One API (deprecated)

Introducing a new way to create APIs on server side and to use them on client side.

One API does not follow the traditional RESTful way. It has only one endpoint for all of its APIs. All you have to do is send a post request with an action and data.

https://api2.eodiro.com/one

Another amazing thing is that the One API provides client side npm module ready to be used right now. Thanks to this module, you don't have to write duplicate type definitions or AJAX calls every time the new APIs are added. Just npm update and you're good to go.

Install

npm install @payw/eodiro-one-api

Dependencies

  • Axios

Usage

import { oneAPIClient } from '@payw/eodiro-one-api'

oneAPIClient(
  action: 'actionName',
  data: { ... }
).then(payload => {
  ...
})

TypeScript will automatically inference the types of request data and payload as you choose the action.

Development Guide


Common

Response

  • Server responds with 500 HTTP response code when there are some problems while processing the APIs

Types

We share some specific types across the APIs.

Type Detailed Type
Day 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'
Semester '1' | 'ν•˜κ³„' | '2' | '동계'
Campus 'μ„œμšΈ' | 'μ•ˆμ„±'

Lectures

Get Lectures

[ GET ]  https://api2.eodiro.com/lectures/:year/:semester/:campus/list

Params

Key Type
year number
semester Semester
campus Campus

Queries

Key Type Description
amount? number The number of lectures you get. Default 20.
offset? number The start index of lectures. Initial 0.

Search Lectures

[ GET ]  https://api2.eodiro.com/lectures/:year/:semester/:campus/search

Params

Key Type
year number
semester Semester
campus Campus

Queries

Key Type Description
q string Search keyword
amount? number The amount of search results. Default 20.
offset? number The offset of search results. Initial 0.

Vacant

Get Buildings Vacant

[ GET ]  https://api2.eodiro.com/vacant/:year/:semester/:campus/buildings

Params

Key Type
year number
semester Semester
campus Campus

Queries

Key Type
day? Day
hour? number
minute? number

Get Classrooms

[ GET ]  https://api2.eodiro.com/vacant/:year/:semester/:campus/buildings/:building/classrooms

Params

Key Type
year number
semester Semester
campus Campus
building string

Queries

Key Type
day? Day

Cafeteria

Get Menus

[ GET ]  https://api2.eodiro.com/cafeteria/:servedAt/:campus/menus

Params

Key Type
servedAt YYYY-MM-DD
campus Campus

Response

Code Description
204 No menus data on the day

Dev Prerequisites

Dev Tools

Node >= 13

MySQL >= 8

Visual Studio Code: We enforce you to use VSCode as an editor for developing the eodiro server.

  • Essential Extensions
    • ESLint
    • Prettier
    • sort-imports
    • Prisma

Config

eodiro

Duplicate src/config/example.ts, rename it to index.ts and fill the information with your environment values.

Prisma

Create prisma/.env and fill with your database information.

DATABASE_URL="mysql://username:password@address:3306/db_name"

NPM Scripts

You can run the scripts below by npm run [script-name].

Application

  • dev: Runs in development mode (listens at port config.DEV_PORT)
    • --nomail: Use this argument if you want to bootstrap the application without an email feature
  • build: Generate JavaScript artifacts into build directory
  • start: Start the production server using the build outputs (listens at port config.PORT)
    • --nomail: Same as above

Database

  • sync-db:prod: Syncs the database models with the database described in config.DB_NAME.
  • sync-db:dev: Same as the previous one but instead syncs with config.DB_NAME_DEV.

CDN

  • cdn:dev: Starts the CDN server in development mode (listens at config.CDN_DEV_PORT)
  • cdn: Starts the CDN server in production mode (listens at config.CDN_PORT)

Prisma

  • introspect: Looks up the database described in prisma/.env and generate a prisma schema file. Never run this script unless there exists any changes in db models. And if you do run, open prisma/schema.prisma and format the file with the Prisma extension in VSCode.
  • generate: Generates Prisma Client with prisma/schema.prisma. Run this script before start developing.

About

A Node.js server application that powers the eodiro.com

Resources

License

Stars

Watchers

Forks

Languages