A Node.js server application that powers the eodiro
Node.js running on NGINX using reverse proxy.
SSL: Let's Encrypt and Certbot python plugin
Resolve 413 Request Entity Too Large
server {
client_max_body_size 3M;
}
Don't forget
- to set timezone correctly of both system and database
It uses MySQL internally as its database.
REST
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.
- Server responds with
500
HTTP response code when there are some problems while processing the APIs
We share some specific types across the APIs.
Type | Detailed Type |
---|---|
Day |
'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' |
Semester |
'1' | 'νκ³' | '2' | 'λκ³' |
Campus |
'μμΈ' | 'μμ±' |
[ 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. |
[ 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. |
[ 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 ] 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 |
[ 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 |
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
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"
You can run the scripts below by npm run [script-name]
.
Application
dev
: Runs in development mode (listens at portconfig.DEV_PORT
)--nomail
: Use this argument if you want to bootstrap the application without an email feature
build
: Generate JavaScript artifacts intobuild
directorystart
: Start the production server using the build outputs (listens at portconfig.PORT
)--nomail
: Same as above
Database
sync-db:prod
: Syncs the database models with the database described inconfig.DB_NAME
.sync-db:dev
: Same as the previous one but instead syncs withconfig.DB_NAME_DEV
.
CDN
cdn:dev
: Starts the CDN server in development mode (listens atconfig.CDN_DEV_PORT
)cdn
: Starts the CDN server in production mode (listens atconfig.CDN_PORT
)
Prisma
introspect
: Looks up the database described inprisma/.env
and generate a prisma schema file. Never run this script unless there exists any changes in db models. And if you do run, openprisma/schema.prisma
and format the file with the Prisma extension in VSCode.generate
: Generates Prisma Client withprisma/schema.prisma
. Run this script before start developing.