Server Setup

You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
A Python Error Occurred:

Error on line 3 of Python tag (line 4 of source):
    student_servername =  BASE_SERVER+"/"+STUDENT_SERVERS[cs_username]['endpoint']

KeyError: 'None'

Your FastAPI application development in the previous assignment was all done local on your own machine.

In the long-term, when you're working with your teams on your final projects, we'll set up actual stand-alone servers that you are to use. They will still use FastAPI, but we'll need to do a bit of setup on them to get it working in-perpetuity and in a stable fashion.

For now, however, we want to resolve the issue of local and world-viewability by using some ssh reverse tunneling. This is not a long-term solution, but to get us going in the short term for development, it will work great.

Step 1

Change some minor details about your FastAPI application. Instead of original application, we need to override some default parameters. You can set title to be whatever...the others use the values shown below:

#app = FastAPI() #comment me out...

app = FastAPI(
    title="EFI Development",
    openapi_url=f"/openapi.json",
    docs_url=f"/docs",
    redoc_url=f"/redoc",
    root_path="/tunnel_None" # <------ root_path adjustment fixes the prepend on the tunnel
)

Start up your FastAPI application. By default it will be served locally on your computer at port 8000. You should see it on your browser. This should be old news to you at this point.

Step 2

We set up a server http://efpi-10.mit.edu that we'll use for a few infrastructure pieces this year. One of them is in lab 01 where everyone can log temperature, humidity, and battery voltage information.

Another endpoint on that server we have provided is a reverse proxy "tunnel." What this does is provide globally-accessible endpoint (in your case

A Python Error Occurred:

Error on line 1 of Python tag (line 37 of source):
    print('%s' % (student_tunnel,))

NameError: name 'student_tunnel' is not defined

) that you can use to connect your FastAPI Application. To do this is pretty easy. We just need to ssh in.

In a separate terminal, run the following command. This will connect your local port 8000 (which is what your application is existing on) to a remote endpoint. Also, you're more than welcome to set up ssh keys on your account on the efpi-10.mit.edu machine if you know how to do that and/or if you want to help us do that to avoid typing in the future. Regardless do the following:

ssh -R  <div><font color='red'><b>A Python Error Occurred:</b><p>
Error on line 1 of Python tag (line 42 of source):
    print('%s' % (student_port,))

NameError: name 'student_port' is not defined
<p></font></div>:localhost:8000 None@efpi-10.mit.edu

(Your password is your MIT ID btw). Once you're logged in, you'll need to stay logged in to keep the tunnel active.

Now in your web browser, go ahead and visit:

A Python Error Occurred:

Error on line 1 of Python tag (line 47 of source):
    print('%s' % (student_tunnel,))

NameError: name 'student_tunnel' is not defined

. When you do this you should basically see the homepage of your FastAPI application from before. This might not seem so amazing since you would have already been seeing this in your browser using the localhost:8000 endpoint, but the critical piece that's different is that now you're able to visit your script on a world-viewable-endpoint.

If this is all working, you're good to go. You now have two computational devices that can talk to one another from anywhere in the world, provided they are connected to the internet. This is not hyperbole. You could go to Australia, and assuming you have good internet, you could totally talk to your laptop that you left up here at MIT. Your laptop is now a "server" aka the "cloud".

To test this functionality, make sure your app and your tunnel are active. Then push the submit button below. The text you put in the box has no influence, I just was too busy to remove that piece of html.

A Python Error Occurred:

Syntax error in question tag:
  File "<string>", line 7
    output = requests.get(f"<div><font color='red'><b>A Python Error Occurred:</b><p><pre>Error&nbsp;on&nbsp;line&nbsp;1&nbsp;of&nbsp;Python&nbsp;tag&nbsp;(line&nbsp;59&nbsp;of&nbsp;source):
                          ^
SyntaxError: unterminated string literal (detected at line 7)