switch to using nginx reverse proxy
This commit is contained in:
parent
0e72c1c415
commit
7fa3b42a77
@ -2,7 +2,7 @@ import Graph from 'graphology';
|
|||||||
|
|
||||||
// This is wrapper functtions to do requests to the api, from the frontend.
|
// This is wrapper functtions to do requests to the api, from the frontend.
|
||||||
|
|
||||||
export const apiUrl = "http://127.0.0.1:3001"
|
export const apiUrl = `${window.location.origin}/api`;
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
headers: {'Content-Type': 'application/json'}
|
headers: {'Content-Type': 'application/json'}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"description": "database tools for the forest",
|
"description": "database tools for the forest",
|
||||||
"main": "db.js",
|
"main": "db.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start": "sqld -d the_big_db.db --http-listen-addr=127.0.0.1:8000",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
Binary file not shown.
@ -1 +1 @@
|
|||||||
{"id":"7de13931-444c-4dd2-a19a-5cd1e70b7f36","rows_written":149,"rows_read":12929,"storage_bytes_used":20480,"write_requests_delegated":0,"current_frame_no":151,"top_query_threshold":15,"top_queries":[{"rows_written":0,"rows_read":15,"query":"select id, html from pages"},{"rows_written":0,"rows_read":15,"query":"select id, title from pages"},{"rows_written":0,"rows_read":16,"query":"select id, html from pages"},{"rows_written":0,"rows_read":16,"query":"select id, title from pages"},{"rows_written":0,"rows_read":17,"query":"select id, html from pages"},{"rows_written":0,"rows_read":17,"query":"select id, title from pages"},{"rows_written":0,"rows_read":18,"query":"select id, html from pages"},{"rows_written":0,"rows_read":18,"query":"select id, title from pages"},{"rows_written":0,"rows_read":19,"query":"select id, html from pages"},{"rows_written":0,"rows_read":19,"query":"select id, title from pages"}],"slowest_query_threshold":0,"slowest_queries":[{"elapsed_ms":0,"query":"select title from pages","rows_written":0,"rows_read":1},{"elapsed_ms":0,"query":"select title from pages","rows_written":0,"rows_read":2},{"elapsed_ms":1,"query":"\nalter table pages \nadd column html text\n","rows_written":1,"rows_read":4},{"elapsed_ms":1,"query":"\ncreate table if not exists renders (\n id integer primary key,\n title varchar(255),\n description text\n)\n","rows_written":2,"rows_read":1},{"elapsed_ms":1,"query":"insert into pages (title, description) values (?, ?) returning id","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"replace into pages (id, title, description) values (?, ?, ?)","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"replace into pages (id, title, description, html) values (?, ?, ?, ?)","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"select * from pages where id=@val","rows_written":0,"rows_read":1},{"elapsed_ms":1,"query":"select count(*) as num_pages from pages","rows_written":0,"rows_read":1},{"elapsed_ms":7,"query":"replace into pages (id, title, description) values (?, ?, ?)","rows_written":1,"rows_read":1}],"embedded_replica_frames_replicated":0,"query_count":1934,"query_latency":161187}
|
{"id":"7de13931-444c-4dd2-a19a-5cd1e70b7f36","rows_written":149,"rows_read":14035,"storage_bytes_used":20480,"write_requests_delegated":0,"current_frame_no":151,"top_query_threshold":0,"top_queries":[{"rows_written":0,"rows_read":16,"query":"select id, html from pages"},{"rows_written":0,"rows_read":16,"query":"select id, title from pages"},{"rows_written":0,"rows_read":17,"query":"select id, html from pages"},{"rows_written":0,"rows_read":17,"query":"select id, title from pages"},{"rows_written":0,"rows_read":18,"query":"select id, html from pages"},{"rows_written":0,"rows_read":18,"query":"select id, title from pages"},{"rows_written":0,"rows_read":19,"query":"select id, html from pages"},{"rows_written":0,"rows_read":19,"query":"select id, title from pages"},{"rows_written":0,"rows_read":19,"query":"select id, html from pages"},{"rows_written":0,"rows_read":19,"query":"select id, title from pages"}],"slowest_query_threshold":0,"slowest_queries":[{"elapsed_ms":0,"query":"select title from pages","rows_written":0,"rows_read":1},{"elapsed_ms":0,"query":"select title from pages","rows_written":0,"rows_read":2},{"elapsed_ms":1,"query":"\nalter table pages \nadd column html text\n","rows_written":1,"rows_read":4},{"elapsed_ms":1,"query":"\ncreate table if not exists renders (\n id integer primary key,\n title varchar(255),\n description text\n)\n","rows_written":2,"rows_read":1},{"elapsed_ms":1,"query":"insert into pages (title, description) values (?, ?) returning id","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"replace into pages (id, title, description) values (?, ?, ?)","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"replace into pages (id, title, description, html) values (?, ?, ?, ?)","rows_written":1,"rows_read":1},{"elapsed_ms":1,"query":"select * from pages where id=@val","rows_written":0,"rows_read":1},{"elapsed_ms":1,"query":"select count(*) as num_pages from pages","rows_written":0,"rows_read":1},{"elapsed_ms":7,"query":"replace into pages (id, title, description) values (?, ?, ?)","rows_written":1,"rows_read":1}],"embedded_replica_frames_replicated":0,"query_count":1996,"query_latency":165200}
|
Binary file not shown.
96
readme.md
96
readme.md
@ -1,94 +1,12 @@
|
|||||||
# What is happening why would a loving god create such a thing
|
# What is happening why would a loving god create such a thing
|
||||||
|
|
||||||
I think `npm start` in each directory should do it
|
I think `npm start` in each directory should run the app
|
||||||
|
|
||||||
# meeee
|
|
||||||
|
|
||||||
I'm leaving all the create-react-app stsuff at the bottom.
|
|
||||||
|
|
||||||
# build log
|
# build log
|
||||||
|
|
||||||
`npx create-react-app the-forest`
|
- `brew tap libsql/sqld`
|
||||||
`brew tap libsql/sqld`
|
- `brew install sqld-beta`
|
||||||
`brew install sqld-beta`
|
- to run cast `npm start` in each directory
|
||||||
to run cast `sqld -d /tmp/data.db --http-listen-addr=127.0.0.1:8000` and alsso `npm start`
|
- `node initialize_db.js` `node populate_db.js`
|
||||||
`node initialize_db.js` `node populate_db.js`
|
- `npm install` should install all dependencies
|
||||||
`npm install react-router-dom`
|
- also you need nginx. `brew install nginx` and then `ln -s the-forest.nginx.conf /usr/local/etc/nginx/servers/the-forest.nginx.conf` or wherever it needs to go
|
||||||
`npm install @tanstack/react-query` i think
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Getting Started with Create React App
|
|
||||||
|
|
||||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
|
||||||
|
|
||||||
## Available Scripts
|
|
||||||
|
|
||||||
In the project directory, you can run:
|
|
||||||
|
|
||||||
### `npm start`
|
|
||||||
|
|
||||||
Runs the app in the development mode.\
|
|
||||||
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
|
||||||
|
|
||||||
The page will reload when you make changes.\
|
|
||||||
You may also see any lint errors in the console.
|
|
||||||
|
|
||||||
### `npm test`
|
|
||||||
|
|
||||||
Launches the test runner in the interactive watch mode.\
|
|
||||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
|
||||||
|
|
||||||
### `npm run build`
|
|
||||||
|
|
||||||
Builds the app for production to the `build` folder.\
|
|
||||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
|
||||||
|
|
||||||
The build is minified and the filenames include the hashes.\
|
|
||||||
Your app is ready to be deployed!
|
|
||||||
|
|
||||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
|
||||||
|
|
||||||
### `npm run eject`
|
|
||||||
|
|
||||||
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
|
||||||
|
|
||||||
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
|
||||||
|
|
||||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
|
||||||
|
|
||||||
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
|
||||||
|
|
||||||
## Learn More
|
|
||||||
|
|
||||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
|
||||||
|
|
||||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
|
||||||
|
|
||||||
### Code Splitting
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
|
||||||
|
|
||||||
### Analyzing the Bundle Size
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
|
||||||
|
|
||||||
### Making a Progressive Web App
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
|
||||||
|
|
||||||
### Advanced Configuration
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
|
||||||
|
|
||||||
### Deployment
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
|
||||||
|
|
||||||
### `npm run build` fails to minify
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
|
56
server/api.js
Normal file
56
server/api.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const showdown = require('showdown');
|
||||||
|
const { query } = require('./dbHelper.js');
|
||||||
|
const { graphFromList } = require('./graphStuff.js');
|
||||||
|
|
||||||
|
const app = express.Router();
|
||||||
|
const converter = new showdown.Converter();
|
||||||
|
|
||||||
|
app.get('/pages', (req, res) => {
|
||||||
|
query('select id, title from pages', [])
|
||||||
|
.then((r) => r.rows)
|
||||||
|
.then((row) => row.map(([id, title]) => {return {"id": id, "title": title};}))
|
||||||
|
.then((pages) => res.status(200).json(pages))
|
||||||
|
.catch((error) => res.status(500).json({"error": error}));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/page/new', (req, res) => {
|
||||||
|
query('insert into pages (title, description) values (?, ?) returning id',
|
||||||
|
["new page", "this page is new!"])
|
||||||
|
.then((r) => r.rows[0])
|
||||||
|
.then((row) => res.status(200).json({id: row[0]}))
|
||||||
|
.catch((error) => res.status(500).json({"error": error}))
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/page/:id', (req, res) => {
|
||||||
|
query('select * from pages where id=?', [req.params.id])
|
||||||
|
.then((r) => {
|
||||||
|
if (r.rows.length == 0) res.status(404).json({"error": "page not found in db"});
|
||||||
|
else return r.rows[0];
|
||||||
|
}).then((row) => res.status(200).json(row))
|
||||||
|
.catch((error) => res.status(500).json({"error": error}));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/page/:id', (req, res) => {
|
||||||
|
const html = converter.makeHtml(req.body.description);
|
||||||
|
query('replace into pages (id, title, description, html) values (?, ?, ?, ?)',
|
||||||
|
[req.params.id, req.body.title, req.body.description, html])
|
||||||
|
.then(() => res.status(200).json({}))
|
||||||
|
.catch((error) => res.status(500).json({"error": error}));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.delete('/page/:id', (req, res) => {
|
||||||
|
query('delete from pages where id = ?', [req.params.id])
|
||||||
|
.then(() => res.status(200).json({id: req.params.id}))
|
||||||
|
.catch((error) => res.status(500).json({"error": error}))
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get('/graph', (req, res) => {
|
||||||
|
query('select id, html from pages', [])
|
||||||
|
.then((r) => r.rows)
|
||||||
|
.then((stuff) => graphFromList(stuff))
|
||||||
|
.then((graph) => res.json(graph))
|
||||||
|
.catch((error) => res.status(500).json({"error": error}));
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = app;
|
@ -1,6 +1,6 @@
|
|||||||
// helper function(s?) to make a query to the database
|
// helper function(s?) to make a query to the database
|
||||||
|
|
||||||
const db_url = 'http://localhost:8000'
|
const db_url = 'http://127.0.0.1:8000'
|
||||||
|
|
||||||
async function query(q, params) {
|
async function query(q, params) {
|
||||||
return fetch(db_url, {
|
return fetch(db_url, {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const showdown = require('showdown');
|
const apiRoutes = require('./api.js');
|
||||||
const { query } = require('./dbHelper.js');
|
|
||||||
const { graphFromList } = require('./graphStuff.js');
|
|
||||||
|
|
||||||
const port = process.env.PORT || 3001; // Use the port provided by the host or default to 3000
|
const port = process.env.PORT || 3001; // Use the port provided by the host or default to 3000
|
||||||
|
|
||||||
@ -14,55 +12,8 @@ app.use(function (req, res, next) {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
const converter = new showdown.Converter();
|
app.use("/api", apiRoutes);
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Server listening on port ${port}`);
|
console.log(`Server listening on port ${port}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/pages', (req, res) => {
|
|
||||||
query('select id, title from pages', [])
|
|
||||||
.then((r) => r.rows)
|
|
||||||
.then((row) => row.map(([id, title]) => {return {"id": id, "title": title};}))
|
|
||||||
.then((pages) => res.status(200).json(pages))
|
|
||||||
.catch((error) => res.status(500).json({"error": error}));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/page/new', (req, res) => {
|
|
||||||
query('insert into pages (title, description) values (?, ?) returning id',
|
|
||||||
["new page", "this page is new!"])
|
|
||||||
.then((r) => r.rows[0])
|
|
||||||
.then((row) => res.status(200).json({id: row[0]}))
|
|
||||||
.catch((error) => res.status(500).json({"error": error}))
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/page/:id', (req, res) => {
|
|
||||||
query('select * from pages where id=?', [req.params.id])
|
|
||||||
.then((r) => {
|
|
||||||
if (r.rows.length == 0) res.status(404).json({"error": "page not found in db"});
|
|
||||||
else return r.rows[0];
|
|
||||||
}).then((row) => res.status(200).json(row))
|
|
||||||
.catch((error) => res.status(500).json({"error": error}));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/page/:id', (req, res) => {
|
|
||||||
const html = converter.makeHtml(req.body.description);
|
|
||||||
query('replace into pages (id, title, description, html) values (?, ?, ?, ?)',
|
|
||||||
[req.params.id, req.body.title, req.body.description, html])
|
|
||||||
.then(() => res.status(200).json({}))
|
|
||||||
.catch((error) => res.status(500).json({"error": error}));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.delete('/page/:id', (req, res) => {
|
|
||||||
query('delete from pages where id = ?', [req.params.id])
|
|
||||||
.then(() => res.status(200).json({id: req.params.id}))
|
|
||||||
.catch((error) => res.status(500).json({"error": error}))
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/graph', (req, res) => {
|
|
||||||
query('select id, html from pages', [])
|
|
||||||
.then((r) => r.rows)
|
|
||||||
.then((stuff) => graphFromList(stuff))
|
|
||||||
.then((graph) => res.json(graph))
|
|
||||||
.catch((error) => res.status(500).json({"error": error}));
|
|
||||||
});
|
|
12
the-forest.nginx.conf
Normal file
12
the-forest.nginx.conf
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# another virtual host using mix of IP-, name-, and port-based configuration
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 8080;
|
||||||
|
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://localhost:3001/api/;
|
||||||
|
}
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:3000/;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user