B. Server Setup

Please read the server's README file in /server/README.md as reference for more information on the server environment variables.

ℹ️

The 08 Server Setup for Localhost Development (opens in a new tab) video tutorial shows how to initialize the server for localhost development in more detail.

Setup environment variables

Create a .env file inside the /server directory. Copy the contents of the .env.example file in it.

  1. Replace the FIREBASE_SERVICE_ACC variable with the Firebase project's private key from it's service account JSON file.
  2. Replace the FIREBASE_PRIVATE_KEY variable with the FIREBASE_SERVICE_ACC's private_key entry.
  3. Replace the FIREBASE_STORAGE_BUCKET variable with your Firebase project's storage bucket
  4. Replace the REGION_NAME variable with a string (no white space) representing the name of your new target region
    ℹ️

    The server REGION_NAME should be similar with the client REGION_NAME value.

  5. Set AXIOS_SSL_REJECT_INVALID to 0
    • If AXIOS_SSL_REJECT_INVALID does not yet exist, please make sure that your forked repository have the most recent update from the upstream repository.
    • The AXIOS_SSL_REJECT_INVALID variable was added recently in ACAP-Bicol 1.0 v9.3.13 to fix a new bug that fails web scraping PAGASA's tropical cyclone and El Nino / La Nina web pages.
  6. Initially set CHECK_RANGE_YEAR to 0.
    • This variable validates that the 10-day PAGASA Excel files downloads contain the latest year.
    • Running the npm run seed:all script below will throw an error if this variable set to 1, since the sample local 10-day PAGASA Excel files used for seeding initial data have outdated dates
    • Set it back to CHECK_RANGE_YEAR=1 after running the seed:all script.
  7. Set SPECIAL_CHARACTERS to ├â┬▒:ñ,â:
    • This variable converts the ├â┬▒ garbled text to ñ from municipality names containing the ñ character in the PAGASA 10-day weather forecast Excel files.
    • Add other key-value pairs of special characters and their normalized values, delimited by a comma as needed
    • Read on this reference (opens in a new tab) for more information about this bug.
  8. ACAP 2.0 introduces several new environment variables. Add the following, while refering to the server's README file in /server/README.md for more information about these variables. Some variables need to be added or excluded in order to enable or disable the ACAP-RCMAS APIs.
    • SPECIAL_CHARACTERS
    • DEPLOYMENT_PLATFORM=default
    • PROVINCES_ARCHIVE - Set its value after running 2. Initialize provinces and municipalities
    • ACAP_API_KEYS
    • IS_RMCAS_API_ACTIVE=0
    • ARCHIVE_TENDAY_FORECAST=0
    • ROOT_API_URL
    • ROOT_API_URL_VERCEL
    • CHECK_RANGE_YEAR

Initialize provinces and municipalities

💡

ACAP refers to the PAGASA Seasonal Forecast - Forecast Rainfall Analysis Table (opens in a new tab) for its regional provinces list, matching the province names with those listed in the PAGASA 10-day Weather Forecast Excel (opens in a new tab) files.

ACAP expects province naming from the two (2) data sources to match since both are data products produced by PAGASA.

Run ACAP's "pagasa:municipalities" NPM script to get a list of the PAGASA municipalities and province names.

  1. First, navigate to the server directory from the command line, then run:

    npm run pagasa:municipalities

    INFO: The "pagasa:municipalities" NPM script uses a static-encoded region/province mapping file, manually encoded in 2024 with reference from the PAGASA Seasonal Forecast - Forecast Rainfall Analysis table.

  2. Enter PAGASA's 10-day Excel file URL when prompted.

  3. Double-check the resulting province names from step #2 with those listed in the latest PAGASA Seasonal Forecast - Forecast Rainfall Analysis (opens in a new tab) table. Take note of new province(s) not included in the generated list, or remove provinces no longer present in the Forecast Rainfall Analysis table.

    ⚠️

    The "pagasa:municipalities" NPM script may generate an outdated or incorrect list of provinces of a region depending on several factors.

  4. Replace the PROVINCES and PROVINCES_ARCHIVE variables with the comma-separated province names of your new target region resulting from steps #2 and #3.

  5. Replace the DEFAULT_PROVINCE .env variable with any province name from the PROVINCES comma-separated province names.

Create new superadmin password

  1. Open the the file: /server/src/scripts/seeders/00_superadmin/index.js
  2. Add a password parameter to the params object. Enter a random password, and remember its value.
    const params = {
      ...,
      displayname: 'Super Admin',
      account_level: 1,
      password: 'some_super_secret_password'
    }

Seed default data

This script initializes the Firestore database with default values. Navigate to the server folder from the command line and run the NPM script:

npm run seed:all
  • This script will create default, mock (empty) values to designated Firestore collections and documents using the defined region and provinces in the .env file, which should be updated later with real values.
  • This script expects to finish without errors. Re-trace, debug and troubleshoot errors, if any will show, before proceeding to the Client Set-up section.

Initialize 10-day weather forecast

Run this server NPM script to fetch and upload the @latest PAGASA 10-day weather forecast data to the Firestore database. Navigate to the server folder from the command line and run the NPM script:

npm run cron:tenday
⚠️

This script may fail to fetch and parse 10-day weather forecast data of several municipalities linked with provinces not available in the 10-day Excel file.

Visit the Provinces and Municipalities article for more information if you notice missing 10-day weather forecast data for several provinces and municipalities.

Build the API docs (Optional)

(Optional) Build ACAP server's REST API documentation website for reference.

  1. Navigate to the server folder from the command line and run the NPM script:
    npm run gen:docs
  2. Go to the /server/src/public/docs folder and click the index.html file to view the generated API documentation.
    • The API documentation website is also available on http://localhost:3001/docs after running the server app.