Skip to content

Commit

Permalink
updated db and api wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
jzakotnik committed Aug 2, 2021
1 parent 2b90824 commit b84ed3d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
30 changes: 30 additions & 0 deletions nextjs/mwe/pages/api/dumpData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction

//This is for debugging purposes

var level = require("level-rocksdb");

export default function handler(req, res) {
var db = level("./lunchdb");
//console.log(req.body);
/*db.get("juresUUID", function (err, value) {
if (err) return console.log("Ooops!", err); // likely the key was not found
console.log(value);
});*/
db.createReadStream()
.on("data", (data) => {
console.log(data.key, "=", data.value);
})
.on("error", function (err) {
console.log("Oh my!", err);
})
.on("close", function () {
console.log("Stream closed");
})
.on("end", function () {
console.log("Stream ended");
db.close();
});

res.end().status(200);
}
34 changes: 34 additions & 0 deletions nextjs/mwe/pages/profile/[id].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { useState } from "react";
import { useRouter } from "next/router";
import LunchProfile from "../lunchprofile";

const Profile = (data) => {
const router = useRouter();
const { id } = router.query;
console.log("Rendering data");
console.log(data);

return (
<LunchProfile
lunchdata={data.lunchprofile}
admin={data.admin}
userName="Jure"
/>
);
};

// This gets called on every request
export async function getServerSideProps() {
// Fetch data from external API
const res = await fetch(
"http://localhost:3000/api/getData?id=48bf4e6a-c92e-4d7c-9fad-6e141685fb31"
);
const data = await res.json();
console.log("Received response from API");
console.log(data);

// Pass data to the page via props
return { props: data };
}

export default Profile;

0 comments on commit b84ed3d

Please sign in to comment.