Commit a26b38b2 authored by Matthieu Fesselier's avatar Matthieu Fesselier

syntax: make server write #502

parent 6e108b4a
Pipeline #6241 passed with stage
in 1 minute and 42 seconds
......@@ -11,10 +11,10 @@
<body>
<solid-display
data-src="http://127.0.0.1:8000/conversations/1/"
fields="title"
widget-title="solid-display-div"
editable-title
data-src="./data/project.jsonld"
fields="name"
widget-name="solid-display-div"
editable-name
></solid-display>
</body>
</html>
......@@ -11,7 +11,7 @@
<body>
<solid-delete
data-src="http://127.0.0.1:8000/conversations/4/"
data-src="data/project.jsonld"
data-label="Supprimer"
></solid-delete>
......
......@@ -11,35 +11,34 @@
</head>
<body>
<solid-router default-route="all" use-hash>
<solid-route name="all">view all</solid-route>
<solid-route name="edit">edit</solid-route>
<solid-route name="add">add new</solid-route>
<solid-route name="view">view it</solid-route>
</solid-router>
<div id="all" hidden>
<sib-router default-route="all" use-hash>
<sib-route name="all">view all</sib-route>
<sib-route name="edit">edit</sib-route>
<sib-route name="add">add new</sib-route>
<sib-route name="view" use-id>view it</sib-route>
</sib-router>
<div id="all">
<solid-display
data-src="https://api.test-paris.happy-dev.fr/skills/"
data-src="data/list/skills.jsonld"
fields="name"
next="edit"
></solid-display>
</div>
<div id="edit" hidden>
<div id="edit">
<solid-form
bind-resources
fields="name"
next="view"
></solid-form>
</div>
<div id="add" hidden>
<div id="add">
<solid-form
data-src="https://api.test-paris.happy-dev.fr/skills/"
data-src="data/list/skills.jsonld"
fields="name"
next="view"
></solid-form>
</div>
<div id="view" hidden>
<div id="view">
<solid-display
bind-resources
fields="name"
......
......@@ -31,13 +31,13 @@ form > * {
label {
display: block;
}
solid-route {
sib-route {
display: inline-block;
background-color: #aaa;
padding: 0.5em;
cursor: pointer;
}
solid-route[active] {
sib-route[active] {
background-color: #ccc;
}
......
......@@ -4,13 +4,17 @@ const distPath = '.';
const { resolve } = require('path');
var url = require('url');
const express = require('express');
const bodyParser = require('body-parser');
const port = require('find-free-port')(3000);
const app = express();
(async () => {
const updateURLs = /.*jsonld/;
const server = app
.use(express.static(distPath))
.use(bodyParser.json({ type: 'application/*+json' }))
.get('/favicon.ico', (req, rep) => rep.send())
.get('/examples/', (req, rep) => rep.redirect('/'))
// Handle upload
.post('/upload', (req, rep) => {
const originalUrl = url.format({
protocol: req.protocol,
......@@ -23,6 +27,11 @@ const app = express();
.get(/^\/upload\/.+/, (req, rep) => {
rep.sendFile(resolve('./fake-image.svg'));
})
// Listen for write requests
.patch(updateURLs, handleUpdate)
.post(updateURLs, handleUpdate)
.put(updateURLs, handleUpdate)
.delete(updateURLs, handleUpdate)
.listen((await port)[0], '0.0.0.0');
server.on('listening', () => {
console.log(address(server.address()));
......@@ -37,3 +46,11 @@ function address(address) {
function uniqID() {
return crypto.randomBytes(5).toString('hex');
}
function handleUpdate(req, rep) {
if (req.headers["content-type"] != "application/ld+json") {
rep.status(500).send('Content not JSON')
}
rep.setHeader('location', req.body['@id'] || "");
rep.send(req.body);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment