-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |