parent
0e72c1c415
commit
3bf6ef3da9
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":13997,"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":1994,"query_latency":165074} |
Binary file not shown.
@ -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; |
@ -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