This file contains hidden or 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
| const namedPlaces = [ | |
| "Junk Junction", | |
| "Haunted Hills", | |
| "Pleasant Park", | |
| "Lazy Links", | |
| "Risky Reels", | |
| "Wailing Woods", | |
| "Tomato Temple", | |
| "Lonely Lodge", | |
| "Retail Row", |
This file contains hidden or 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
| body{ | |
| font-family: "Verdana" | |
| } | |
| #app{ | |
| display: flex; | |
| flex-direction: column; | |
| justify-content: center; | |
| align-items: center; | |
| } |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <meta name="viewport" content="width=device-width, user-scalable=no" /> | |
| <link rel="manifest" href="manifest.json" /> | |
| <title>FN Jumper</title> | |
| <link rel="stylesheet" type="text/css" media="screen" href="styles.css" /> |
This file contains hidden or 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
| import axios from 'axios'; | |
| import Router from 'next/router'; | |
| import { Cookies } from 'react-cookie'; | |
| // set up cookies | |
| const cookies = new Cookies(); | |
| const serverUrl = 'http://localhost:3001'; | |
| export async function handleAuthSSR(ctx) { | |
| let token = null; |
This file contains hidden or 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
| import React from 'react'; | |
| import axios from 'axios'; | |
| import { Cookies } from 'react-cookie'; | |
| import { handleAuthSSR } from '../utils/auth'; | |
| const serverUrl = 'http://localhost:3001'; | |
| // set up cookies | |
| const cookies = new Cookies(); |
This file contains hidden or 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
| import React from 'react'; | |
| import Link from 'next/link.js'; | |
| import axios from 'axios'; | |
| import { Cookies } from 'react-cookie'; | |
| const serverUrl = 'http://localhost:3001'; | |
| // set up cookies | |
| const cookies = new Cookies(); | |
| class Index extends React.Component { |
This file contains hidden or 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
| // Routes | |
| app.get("/api/login", (req, res) => { | |
| // generate a constant token, no need to be fancy here | |
| const token = jwt.sign({ "username": "Mike" }, jwtSecret, { expiresIn: 60 }) // 1 min token | |
| // return it back | |
| res.json({ "token": token }) | |
| }); | |
| app.get("/api/token/ping", (req, res) => { | |
| // Middleware will already catch if token is invalid |
This file contains hidden or 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
| //... | |
| const jwt = require('jsonwebtoken'); | |
| const jwtSecret = "mysuperdupersecret"; // Use env for secrets | |
| //... | |
| // Auth middleware | |
| app.use((req, res, next) => { | |
| // login does not require jwt verification | |
| if (req.path == '/api/login') { | |
| // next middleware |
This file contains hidden or 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
| //... | |
| // CORS middleware | |
| app.use(function (req, res, next) { | |
| // Allow Origins | |
| res.header("Access-Control-Allow-Origin", "*"); | |
| // Allow Methods | |
| res.header("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE, OPTIONS"); | |
| // Allow Headers | |
| res.header("Access-Control-Allow-Headers", "Origin, Accept, Content-Type, Authorization"); |
This file contains hidden or 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
| const express = require("express"); | |
| const bodyParser = require("body-parser"); | |
| const app = express(); | |
| const port = 3001; | |
| // Middleware | |
| // JSON parser middleware | |
| app.use(bodyParser.json()); |