Infrastructure Backend 25Jan - TheEvergreenStateCollege/upper-division-cs-23-24 GitHub Wiki
Step 1: Log into the AWS Console and ensure your EC2 is up and running.
Here is a guide to build one: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html. Name your instance (this is not permanent) T2.micro(default) 30GB gp2 harddrive (for Ubuntu) SSH, HTTP and HTTps checked Click launch instance.
- Then click on the instance, select the security tab at the bottom, click on the security group (named something-wizard) Add custom TCP port 5000, 0.0.0.0/0 cidr and any other port you need.
You need the public/private key to exist on your computer to log in ssh to your ec2. to log in, select your instance in the AWS console, select "connect" at the top, select "ssh", copy the example at the bottom. Paste this command into your terminal and arrow over to replace the "" where the private key should go.
- Make a directory called "workspace"
- Run
ssh-keygen -t rsa -b 4096 -C "[email protected]"
- Run >>>
git clone [email protected]:TheEvergreenStateCollege/upper-division-cs.git
- Change into upper-division-cs/web-24/assignments
- Run >>>
YOUR_SUBDOMAIN= <<your domain name of choice>>.acrology.builders
.
Example: YOUR_SUBDOMAIN="blah.arcology.builders"
- Run >>>
curl -X PUT --user [email protected]:web-infra https://mail.arcology.builders/admin/dns/custom/$YOUR_SUBDOMAIN
- subStep 1 >>> sudo vim /etc/systemd/system/dynamic-dns.service
- Press "I" to switch to vim insert mode
- Paste:
[Unit]
Description=Update DNS entry
After=network.target
[Service]
Type=simple
ExecStart=curl -X PUT --user [email protected]:web-infra https://mail.arcology.builders/admin/dns/custom/<<<YOUR SUBDOMAIN>>>.arcology.builders
RemainAfterExit=true
[Install]
WantedBy=default.target
-
Edit the <<>> and change to your subdomain from step 6.
-
subStep 2: Run >>>
sudo systemctl daemon-reload
-
Run >>>
sudo systemctl enable --now dynamic-dns.service
-
Run >>>
sudo reboot
-
subStep 3: wait 30 seconds and log back into the EC2 server
-
subStep 4: Run >>>
sudo systemctl status dynamic-dns.service
Look for this:
Key items are Active and OK, red is bad See class discord for additional alternatives to using systemD
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash . ~/.nvm/nvm.sh
nvm install v20
npm i -g pnpm
- Run >>>
mkdir -p <repo_root>/web-24wi/assignment/ppham/week3/api-server
- Run >>>
cd -p <repo_root>/web-24wi/assignment/ppham/week3/api-server
- Run >>>
pnpm init
- Run >>>
pnpm i express
- Run >>>
vim server.js
paste in the express server code from here page 1: https://hendrixer.github.io/API-design-v4/lessons/intro-to-express/easy-mode-with-express
- Run >>>
mkdir -p pages
- Run >>>
vim pages/index.html # add hello world in this file
- Run >>>
node server.js
This starts your Node server
Step 11: Then in your browser try http://<YOUR_SUBDOMAIN>.arcology.builders:5000
Some notes: Express URL route parameters https://expressjs.com/en/guide/routing.html
Step 12 Continue copying google search results and pasting them into files that match this directory structure
├── package.json
├── pages
│ ├── index.html
│ ├── search-hit-1.html
│ ├── search-hit-2.html
│ └── search-hit-3.html
├── pnpm-lock.yaml
└── server.js
Step 13: Add the following lines to your server.js to handle another route, with a route parameter :hit
// Return search hit given :hit URL route parameters
app.get("/search-hit/:hit", (req, res) => {
// sending back an HTML file that a browser can render on the screen.
res.sendFile(path.resolve(`pages/search-hit-${req.params.hit}.html`));
});
TIP: Need two terminal windows? You can use tmux to run server.js in one pane and edit it with vim in another pane To install tmux:
- Run >>>
sudo apt install -y tmux
For a terminal filesystem visualizer: - Run >>>
sudo apt install -y tree
- Restart your node server.js (Ctrl +C to kill the existing process, then run it again)
- In your browser, you want to try and get all these search hits by trying:
[http://<YOUR_SUBDOMAIN>.arcology.builders/search-hit/1](http://%3cYOUR_SUBDOMAIN%3e.arcology.builders/search-hit/1)
[http://<YOUR_SUBDOMAIN>.arcology.builders/search-hit/2](http://%3cYOUR_SUBDOMAIN%3e.arcology.builders/search-hit/2)
[http://<YOUR_SUBDOMAIN>.arcology.builders/search-hit/3](http://%3cYOUR_SUBDOMAIN%3e.arcology.builders/search-hit/3)
TIP: Here's a quick tutorial on using vim to create the search-hit-x.html
vim pages/search-hit-1.html
# press i to enter INSERT mode
# in a browser, inspect google search results
# hover over div's until it highlights in blue the search result you want
# right click and choose copy -> innerHTML or copy -> Element
# return to your VIM window
# Ctrl + V or Cmd + V to paste
# :wq in vim to write quit