Skip to content
Snippets Groups Projects
Commit d9da5bd6 authored by Wilson JALLET's avatar Wilson JALLET :money_with_wings:
Browse files

Error pages & form to lookup db

parent e4d40a4d
No related branches found
No related tags found
No related merge requests found
h1 {
color: red;
}
\ No newline at end of file
* {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif
}
body {
padding: 2em
padding: 3em;
background-color: #f4f4f4;
}
* {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif
}
\ No newline at end of file
form {
margin-bottom: 1em;
}
.form-group {
margin-top: 0.7em;
margin-bottom: 0.7em;
}
.form-group label {
margin-right: 1em;
}
input.form-control {
width: auto;
background: none;
border: none;
padding-bottom: 2px;
border-bottom: solid 1.3px rgba(0, 0, 0, 0.2);
transition: border 0.2s ease-out;
font-family: "Segoe UI";
}
input.form-control:focus {
outline: none;
border-bottom-color: rgba(1, 40, 148, 0.842);
}
button.form-control {
display: block;
color: white;
width: 80px;
height: 30px;
background-color: rgba(0, 2, 138, 0.767);
border: solid 1px rgba(117, 117, 117, 0.226);
border-radius: 4px;
}
.form-group button {
margin-top: 0;
margin-left: 0.6em
}
button.form-control:hover {
background-color: rgba(37, 0, 138, 0.87);
}
button.form-control:active {
box-shadow: inset 0 8px 6px -6px black;
transition: background-color;
}
......@@ -3,6 +3,7 @@ import colors from 'colors';
import { graphqlExpress, graphiqlExpress } from 'graphql-server-express';
import makeExecutableSchema from 'graphql-tools';
import knex from '../db/knex_router';
import path from 'path';
/**
* @function Home
......@@ -10,7 +11,14 @@ import knex from '../db/knex_router';
*/
server.get('/', function(req, res) {
console.log('Connecting to '+req.url);
res.render('home');
res.render('home', {title: 'Home', port: port});
});
server.get('/db?', function(req, res) {
let table_name = req.query.table;
let columns = req.query.columns;
res.redirect(`db/${table_name}?columns=${columns}`);
});
/**
......@@ -34,8 +42,11 @@ server.get('/db/:table_name?', function(req, res) {
res.write(JSON.stringify(table,null,2));
res.end();
},function() {
res.status(404);
res.write(`Error: Relation ${req.params.table_name} does not exist`);
res.status(400);
res.render('error', {
status: res.statusCode,
error_message: "Bad request: can't find table " + req.params.table_name
});
res.end();
}
);
......@@ -60,10 +71,11 @@ server.use((err, req, res, next) => {
res.locals.message = err.message;
res.status(err.status || 500);
res.write(`Error 404
Not found.`);
res.end();
let error_message = res.statusCode == 404 ? 'Not found.' : 'Internal server error.';
res.render('error', {
status: res.statusCode,
error_message: error_message
});
});
// define port server is to listen on
......
extends layout.pug
block extraStyles
include ../css/error.css
block content
h1 Error #{status}
p #{error_message}
a(href="/") Go back
\ No newline at end of file
style
include ../css/style.css
\ No newline at end of file
block title
include head.pug
title Accueil
extends layout.pug
block content
h1 Welcome to API server
p Hello, world ! This is server talking to you live on port 3000 !
a(href="db/groups") Groups
\ No newline at end of file
h1 Welcome to API server
p Hello, world ! This is server talking to you live on port #{port} !
form(action="/db", method="get")
div.form-group
label(for="table") Table
input.form-control(type="search", name="table")
div.form-group
label(for="columns") Columns
input.form-control(type="search", name="columns")
button.form-control(type="submit") Search
|
a(href="/graphql") Check GraphQL
\ No newline at end of file
......@@ -4,6 +4,9 @@ html(lang="en")
meta(charset="UTF-8")
meta(name="viewport", content="width=device-width, initial-scale=1.0")
meta(http-equiv="X-UA-Compatible", content="ie=edge")
block title
style
include ../css/style.css
block extraStyles
title API server - #{title}
body
block content
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment