Skip to content

Commit

Permalink
Merge pull request #100 from solid-contrib/solid-spec-v0.10
Browse files Browse the repository at this point in the history
update server
  • Loading branch information
bourgeoa authored Mar 2, 2024
2 parents 49dadfd + d842955 commit 21e77e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<link type="text/css" rel="stylesheet" href="./node_modules/mashlib/dist/mash.css" />
<script type="text/javascript" src="https://solidcommunity.net/mashlib.js"></script>
<script type="text/javascript" src="./node_modules/mashlib/dist/mashlib.js"></script>
<script type="module">
const port = 3000;
var host = `http://localhost:${port}`;
Expand Down
17 changes: 15 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@ const {SolidNodeClient} = require('solid-node-client');
const client = new SolidNodeClient();
const express = require('express');
const URL = require('url');
const path = require('path')
const bodyParser = require('body-parser');

const app = express();
app.use(bodyParser.text());

const port = process.argv[2] || null;
const docRoot = process.argv[3] || null;
let docRoot = process.argv[3] || null;
docRootIndex = __dirname
if(!(port && docRoot)) {
console.log("Syntax: npm run start port documentRoot.");
console.log(" e.g. npm run start 3000 /home/me.");
process.exit();
}

app.all('*', async (req, res, next) => {
const filePath = "file://" + docRoot + req.path;
let filePath = "file://" + docRoot + req.path;
// if (req.path === '/') return res.redirect(301, 'http://localhost:3000/index.html')
if (req.path === '/index.html') {
// req.url = '/index.html'
filePath = "file://" + docRootIndex + req.path
} if (req.path.startsWith('/node_modules/mashlib/dist')) {
filePath = "file://" + docRootIndex + req.path
}
// return res.sendFile(path.dirname(require.resolve('./index.html'))+'/index.html')
try{
const solidRestRequest = mungeRestRequest(req);
const solidRestResponse = await client.fetch(filePath,solidRestRequest);
Expand All @@ -40,12 +50,15 @@ function mungeRestResponse(res,solidRestResponse){
res.type('html');
} else if (type.includes('text')) {
res.type('text');
} else if (type.includes('json')) {
res.type('json');
}
return res;
}
function mungeRestRequest(req){
return {
status : req.status,
method : req.method,
headers : req.headers,
url : 'file://' + docRoot + req.path,
slug : req.slug,
Expand Down

0 comments on commit 21e77e2

Please sign in to comment.