add simple SSR node.js service

This commit is contained in:
Guy Bianco IV 2021-06-21 16:45:27 -04:00
parent 2bcd724c8b
commit aefcdeb278
7 changed files with 1748 additions and 0 deletions

104
todo-ssr/.gitignore vendored Normal file
View file

@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port

1
todo-ssr/README.md Normal file
View file

@ -0,0 +1 @@
# todo-ssr

29
todo-ssr/index.js Normal file
View file

@ -0,0 +1,29 @@
const express = require("express");
const axios = require("axios");
const port = Number(process.env.PORT || 8080);
const apiHost = (process.env.API_HOST = "localhost:3000");
const app = express();
app.set("view engine", "pug");
app.get("/", (req, res) => {
res.render("index", { title: "Hello", message: "Page message" });
});
app.get("/items", async (req, res) => {
try {
const items = await axios
.get(`${apiHost}/api/items`)
.then((response) => response.data);
console.log("items:", items);
res.render("items", { items });
} catch (err) {
res.status(500).send(err.message);
}
});
app.listen(port, () => {
console.log("Express server started on port: " + port);
});

1582
todo-ssr/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

16
todo-ssr/package.json Normal file
View file

@ -0,0 +1,16 @@
{
"name": "todo-ssr",
"private": true,
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"license": "MIT",
"dependencies": {
"axios": "^0.21.1",
"express": "^4.17.1",
"pug": "^3.0.2"
}
}

5
todo-ssr/views/index.pug Normal file
View file

@ -0,0 +1,5 @@
html
head
title= title
body
h1= message

11
todo-ssr/views/items.pug Normal file
View file

@ -0,0 +1,11 @@
html
head
title Todo Items
body
h1 Todo List
p Note that this version is non-interactive
ul
each item in items
li
input(type="checkbox" disabled="disabled" checked=item.done ? "checked" : "")
span= item.description