Skip to content

Commit b32b880

Browse files
committed
docs: Cleanup the README
- Replace outdated proxy explanation - Add more explanation and links to tutorials.
1 parent a795564 commit b32b880

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

README.md

+18-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Common UI for iot-api tutorials.
1+
# UI for iot-api tutorials
22

33
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) and
44
customized to route `/api` requests to external middleware -
@@ -14,43 +14,34 @@ specifically, the InfluxData `iot-app-<js, python, etc.>` example applications.
1414
yarn dev
1515
```
1616

17-
2. Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
17+
By default, the server runs on port `:3000`; otherwise, the next available port (for example, `3001`).
18+
Visit [http://localhost:3000](http://localhost:3000) in your browser to see the result.
1819

19-
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
20+
To view the IoT Starter device dashboard, visit [http://localhost:3000/devices/](http://localhost:3000/devices/)
2021

21-
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
22+
1. To customize the UI default page, edit the `pages/index.tsx` file. The page auto-updates as you edit the file.
23+
24+
Next.js provides a sample REST API at [http://localhost:3000/api/hello](http://localhost:3000/api/hello). To customize the sample endpoints, edit `pages/api/hello.ts`.
25+
26+
View IoT Starter devices at [http://localhost:3000/devices/](http://localhost:3000/devices/).
27+
To customize the device pages, edit the files located in [`./pages/devices`](./pages/devices/).
2228

2329
## Use with `iot-api-[language]` apps
2430

2531
To use the UI with one of the `iot-api-[language]` example apps, set `API_URL` in `./.env.development` to the URL of the API example app.
2632

27-
`iot-api-ui` uses a Next.js _catch-all_ route and `http-proxy` to proxy all `/api` requests to your API middleware server.
28-
See `./pages/api/[...path].js` for the `/api` route and proxy configuration.
29-
30-
```js
31-
import httpProxy from 'http-proxy'
32-
33-
/** Set API_URL to the URL of iot-api-js, iot-api-python, etc. **/
34-
const API_URL = process.env.API_URL
35-
const proxy = httpProxy.createProxyServer()
36-
/** Don't parse JSON bodies on the proxied route **/
37-
export const config = {
38-
api: {
39-
bodyParser: false
40-
}
41-
}
42-
export default (req, res) => {
43-
proxy.web(req, res, { target: API_URL, changeOrigin: true })
44-
}
45-
```
33+
The UI automatically routes all `/api/` requests to your API server.
34+
`iot-api-ui` uses Next.js' _catch-all_ routing and [**`rewrites`** module](https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites) to act as a proxy for cross-domain requests to the server.
35+
To customize the URL rewrites, edit `next.config.js`.
4636

4737
## Learn More
4838

39+
Follow step-by-step tutorials to build the IoT Starter app:
40+
41+
- [InfluxDB OSS v2 Python and JavaScript tutorials](https://docs.influxdata.com/influxdb/v2/api-guide/tutorials/)
42+
- [InfluxDB Cloud v2 Python and JavaScript tutorials](https://docs.influxdata.com/influxdb/cloud/api-guide/tutorials/)
43+
4944
To learn more about Next.js, see following resources:
5045

5146
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
5247
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
53-
54-
## Credits
55-
56-
1. https://maxschmitt.me/posts/next-js-api-proxy/ for the `http-proxy` configuration.

0 commit comments

Comments
 (0)