pingcap / sp500-insight-template

SP500 Insight vercel template based on TiDB Cloud Data API: https://sp500-insight.vercel.app
https://sp500-insight.vercel.app
Apache License 2.0
2 stars 9 forks source link

"error - Error: Data service not configured." #9

Closed yahonda closed 10 months ago

yahonda commented 11 months ago

Steps to reproduce

  1. Install, Node.js, npm and pnpm versions as follows.

    % node -v
    v18.17.0
    % npm -v
    9.6.7
    % pnpm -v
    8.6.10
  2. Create a TiDB Serverless instance, named "Cluster0"

  3. Import "S%P 500 Analysis"

Database changed mysql> show tables; +------------------------+ | Tables_in_sp500insight | +------------------------+ | companies | | index_compositions | | index_price_history | | indexes | | stock_price_history | | user_selected_stocks | | users | +------------------------+ 7 rows in set (0.01 sec)

mysql> select count() from companies; +----------+ | count() | +----------+ | 493 | +----------+ 1 row in set (0.02 sec)

mysql> select count() from index_compositions; +----------+ | count() | +----------+ | 493 | +----------+ 1 row in set (0.02 sec)

mysql> select count() from index_price_history; +----------+ | count() | +----------+ | 2517 | +----------+ 1 row in set (0.01 sec)

mysql> select count() from indexes; +----------+ | count() | +----------+ | 1 | +----------+ 1 row in set (0.01 sec)

mysql> select count() from stock_price_history; +----------+ | count() | +----------+ | 1157000 | +----------+ 1 row in set (0.49 sec)

mysql> select count() from user_selected_stocks; +----------+ | count() | +----------+ | 14 | +----------+ 1 row in set (0.01 sec)

mysql> select count() from users; +----------+ | count() | +----------+ | 1 | +----------+ 1 row in set (0.01 sec)

mysql>


4. Clone this repository

git clone https://github.com/pingcap/sp500-insight-template cd sp500-insight-template npm install


5. Set the DATABASE_URL environment variable

export DATABASE_URL=mysql://:@gateway01.us-west-2.prod.aws.tidbcloud.com:4000/sp500insight?timezone=Z


6. Run `npm run dev` and keep this terminal open

% npm run dev

sp500insight@0.1.0 dev next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000 warn - You have enabled experimental features (appDir, serverComponentsExternalPackages, mdxRs) in next.config.js. warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

info - Thank you for testing appDir please leave your feedback at https://nextjs.link/app-feedback event - compiled client and server successfully in 1263 ms (265 modules) wait - compiling... event - compiled client and server successfully in 362 ms (265 modules)

7. Use Google Chrome to open http://localhost:3000

### Expected behavior
Test application should work.

### Actual behavior
`npm run dev` raises error - Error: Data service not configured.

error - Error: Data service not configured. at executeEndpoint (webpack-internal:///(sc_server)/./utils/data-api/server.ts:24:15) at eval (webpack-internal:///(sc_server)/./app/data-api/[...id]/route.ts:36:119) at withUpstreamErrorHandled (webpack-internal:///(sc_server)/./utils/data-api/server.ts:71:22) at handle (webpack-internal:///(sc_server)/./app/data-api/[...id]/route.ts:35:96) at GET (webpack-internal:///(sc_server)/./app/data-api/[...id]/route.ts:18:12) at /Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/future/route-handlers/app-route-route-handler.js:308:24 at AsyncLocalStorage.run (node:async_hooks:338:14) at StaticGenerationAsyncStorageWrapper.wrap (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/async-storage/static-generation-async-storage-wrapper.js:32:24) at StaticGenerationAsyncStorageWrapper.wrap (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/async-storage/static-generation-async-storage-wrapper.js:7:52) at /Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/future/route-handlers/app-route-route-handler.js:217:52 at AsyncLocalStorage.run (node:async_hooks:338:14) at RequestAsyncStorageWrapper.wrap (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/async-storage/request-async-storage-wrapper.js:65:24) at RequestAsyncStorageWrapper.wrap (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/async-storage/request-async-storage-wrapper.js:30:43) at AppRouteRouteHandler.execute (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/future/route-handlers/app-route-route-handler.js:214:69) at AppRouteRouteHandler.handle (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/future/route-handlers/app-route-route-handler.js:350:41) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async RouteHandlerManager.handle (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/future/route-handler-managers/route-handler-manager.js:16:24) at async doRender (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/base-server.js:743:32) at async cacheEntry1.responseCache.get.incrementalCache.incrementalCache (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/base-server.js:929:28) at async /Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/response-cache/index.js:83:36 error - Error: Data service not configured. at executeEndpoint (webpack-internal:///(sc_server)/./utils/data-api/server.ts:24:15) at eval (webpack-internal:///(sc_server)/./app/data-api/[...id]/route.ts:36:119) at withUpstreamErrorHandled (webpack-internal:///(sc_server)/./utils/data-api/server.ts:71:22) at handle (webpack-internal:///(sc_server)/./app/data-api/[...id]/route.ts:35:96) at GET (webpack-internal:///(sc_server)/./app/data-api/[...id]/route.ts:18:12) at /Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/future/route-handlers/app-route-route-handler.js:308:24 at AsyncLocalStorage.run (node:async_hooks:338:14) at StaticGenerationAsyncStorageWrapper.wrap (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/async-storage/static-generation-async-storage-wrapper.js:32:24) at StaticGenerationAsyncStorageWrapper.wrap (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/async-storage/static-generation-async-storage-wrapper.js:7:52) at /Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/future/route-handlers/app-route-route-handler.js:217:52 at AsyncLocalStorage.run (node:async_hooks:338:14) at RequestAsyncStorageWrapper.wrap (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/async-storage/request-async-storage-wrapper.js:65:24) at RequestAsyncStorageWrapper.wrap (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/async-storage/request-async-storage-wrapper.js:30:43) at AppRouteRouteHandler.execute (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/future/route-handlers/app-route-route-handler.js:214:69) at AppRouteRouteHandler.handle (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/future/route-handlers/app-route-route-handler.js:350:41) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async RouteHandlerManager.handle (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/future/route-handler-managers/route-handler-manager.js:16:24) at async doRender (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/base-server.js:743:32) at async cacheEntry1.responseCache.get.incrementalCache.incrementalCache (/Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/base-server.js:929:28) at async /Users/yahonda/src/github.com/pingcap/sp500-insight-template/node_modules/next/dist/server/response-cache/index.js:83:36

yahonda commented 11 months ago

Based on the error message, it looks like DATA_SERVICE_USERNAME, DATA_SERVICE_PASSWORD,DATA_SERVICE_ENDPOINT` environment variables need configured.

https://github.com/pingcap/sp500-insight-template/blob/38d3584bfbcdb467932a0d88aac28b8b998c64a8/utils/data-api/server.ts#L13-L15

Taking a look at https://docs.pingcap.com/tidbcloud/data-service-get-started but still I have not found how to configure them. Please advise.

634750802 commented 11 months ago

The datasrouce config successfully pulled from tidbcloud.

See commit a36e48

Files deployed at https://github.com/pingcap/sp500-insight-template/tree/main/datasource/dataservice

yahonda commented 10 months ago

This issue has been resolved.

  1. Follow the steps below. https://docs.pingcap.com/tidbcloud/data-service-manage-github-connection?__hstc=148441896.59c27c0b6a8d065993e5d36764143a29.1691148583912.1691504124186.1691558933479.9&__hssc=148441896.1.1691558933479&__hsfp=574653929&_gl=1*48c9vr*_gcl_au*ODYwODMyNjQ5LjE2OTExNDg1MDY.&_ga=2.203264209.1978670936.1691395060-446984187.1691148506#import-configurations-of-an-existing-data-app

  2. Go to "Authentication" -> "Create API Key" and choose "ReadOnly" role. then set the "Public Key" value as DATA_SERVICE_USERNAME, the "Private Key" value as DATA_SERVICE_PASSWORD. Also DATA_SERVICE_ENDPOINT=https://ap-northeast-1.data.tidbcloud.com/api/v1beta/app//endpoint`

  3. Run npm run dev and open http://localhost/3000

  4. Click S&P 500 Analysis, Ranking and Constituents to see if they works.

yahonda commented 10 months ago

Still the Selected Stocks gets Unhandled Runtime Error TypeError: data.map is not a function that should be another issue.

yahonda commented 10 months ago

Closing this issue as resolved. Thanks for the kind help.