├── .gitignore
├── Browser
├── bundle.css
├── bundle.js
└── bundle.map
├── app.js
├── handler.js
├── handler.map
├── index.html
├── package-lock.json
├── package.json
├── parcel.js
├── readme.md
├── serverless.yml
└── src
├── App.js
├── app.css
├── index.js
└── users.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .serverless
2 | .cache
3 | node_modules
4 |
--------------------------------------------------------------------------------
/Browser/bundle.css:
--------------------------------------------------------------------------------
1 |
2 |
3 | h1{
4 | text-align: center;
5 | color: red;
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | import serverless from "serverless-http";
2 | import express from "express";
3 | import cors from "cors";
4 | import bodyParser from "body-parser";
5 | import React from "react";
6 | import { renderToString } from "react-dom/server";
7 | import App from "./src/App";
8 | import Data from "./src/users";
9 | import fs from "fs";
10 | import path from "path";
11 |
12 |
13 |
14 | const app = express();
15 |
16 | app.use(cors());
17 | app.use(bodyParser.json());
18 | app.use(bodyParser.urlencoded({ extended: false }));
19 | app.use(express.static(path.resolve(__dirname, "./Browser")));
20 |
21 |
22 | const markup = fs.readFileSync(__dirname + "/index.html",
23 | "utf8"
24 | );
25 |
26 | app.get("**", (req, res) => {
27 | Data().then(users => {
28 | const html = renderToString();
29 | res.send(markup.replace("", html));
30 | });
31 | });
32 |
33 | module.exports.ssr = serverless(app);
34 |
--------------------------------------------------------------------------------
/handler.js:
--------------------------------------------------------------------------------
1 | // modules are defined as an array
2 | // [ module function, map of requires ]
3 | //
4 | // map of requires is short require name -> numeric require
5 | //
6 | // anything defined in a previous bundle is accessed via the
7 | // orig method which is the require for previous bundles
8 |
9 | // eslint-disable-next-line no-global-assign
10 | parcelRequire = (function (modules, cache, entry, globalName) {
11 | // Save the require from previous bundle to this closure if any
12 | var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
13 | var nodeRequire = typeof require === 'function' && require;
14 |
15 | function newRequire(name, jumped) {
16 | if (!cache[name]) {
17 | if (!modules[name]) {
18 | // if we cannot find the module within our internal map or
19 | // cache jump to the current global require ie. the last bundle
20 | // that was added to the page.
21 | var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
22 | if (!jumped && currentRequire) {
23 | return currentRequire(name, true);
24 | }
25 |
26 | // If there are other bundles on this page the require from the
27 | // previous one is saved to 'previousRequire'. Repeat this as
28 | // many times as there are bundles until the module is found or
29 | // we exhaust the require chain.
30 | if (previousRequire) {
31 | return previousRequire(name, true);
32 | }
33 |
34 | // Try the node require function if it exists.
35 | if (nodeRequire && typeof name === 'string') {
36 | return nodeRequire(name);
37 | }
38 |
39 | var err = new Error('Cannot find module \'' + name + '\'');
40 | err.code = 'MODULE_NOT_FOUND';
41 | throw err;
42 | }
43 |
44 | localRequire.resolve = resolve;
45 |
46 | var module = cache[name] = new newRequire.Module(name);
47 |
48 | modules[name][0].call(module.exports, localRequire, module, module.exports, this);
49 | }
50 |
51 | return cache[name].exports;
52 |
53 | function localRequire(x){
54 | return newRequire(localRequire.resolve(x));
55 | }
56 |
57 | function resolve(x){
58 | return modules[name][1][x] || x;
59 | }
60 | }
61 |
62 | function Module(moduleName) {
63 | this.id = moduleName;
64 | this.bundle = newRequire;
65 | this.exports = {};
66 | }
67 |
68 | newRequire.isParcelRequire = true;
69 | newRequire.Module = Module;
70 | newRequire.modules = modules;
71 | newRequire.cache = cache;
72 | newRequire.parent = previousRequire;
73 |
74 | for (var i = 0; i < entry.length; i++) {
75 | newRequire(entry[i]);
76 | }
77 |
78 | if (entry.length) {
79 | // Expose entry point to Node, AMD or browser globals
80 | // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
81 | var mainExports = newRequire(entry[entry.length - 1]);
82 |
83 | // CommonJS
84 | if (typeof exports === "object" && typeof module !== "undefined") {
85 | module.exports = mainExports;
86 |
87 | // RequireJS
88 | } else if (typeof define === "function" && define.amd) {
89 | define(function () {
90 | return mainExports;
91 | });
92 |
93 | //
15 |