Single page applications (SPAs) are generally not the first tool I reach for when building a new website. Unless I’m starved for reactivity, I find managing user credentials, securing my API, and shipping a large bundle to the client to process frankly over-stressful and unnecessary. I’d much rather use a server-side multi-page app (MPA) with HTMX or Alpine.JS to achieve dynamic hydration where it counts without having to worry about exposing logic or secrets to the client.

However, recently I started building a realtime multiplayer board game using websockets. I needed a tech stack that could handle regular state changes from the server while updating a dynamic game board. Out of everything I found, Solid JS seemed to be the simplest, most performant framework I could integrate with Go.

Setting up Vite

You can set up a new Solid project easily by running

bunx degit solidjs/templates/ts my-app

Then move 'package.json', 'tsconfig.json', 'vite.config.ts', 'index.html' and 'postcss.config.js' out of your 'my-app' directory into the root of your Go project. This centers your root as the heart of your project and follows Go best practice. Next, modify the index html so the 'script' tag source is accurate to your 'index.tsx'.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <link
      rel="shortcut icon"
      type="image/ico"
      href="/client/assets/favicon.ico"
    />
    <title>My App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>

    <script src="/my-app/index.tsx" type="module"></script>
  </body>
</html>

Finally, update your 'vite.config.ts'’s server.proxy object to support your application’s API route:

proxy: {  
     "/api": {  
       target: "http://localhost:3000",  
       changeOrigin: true,  
     },  
     "/ws": {  
       target: "http://localhost:3000",  
       changeOrigin: true,  
     },  
   },

Now, you can configure your backend to render your app’s development server and static assets depending on your development or production environment.

Using Go Fiber

DEBUG in this example represents any methodology you might use to determine if you're running your app in production.

	if DEBUG {  
		  
		app.Use(func(c *fiber.Ctx) error {  
			// Proxy requests to Vite dev server  
			if c.Path() == "/" || strings.HasPrefix(c.Path(), "/assets/") {  
				return proxy.Do(c, "http://localhost:5173")  
			}  
			return c.Next()  
		})

		app.Get("/*", func(c *fiber.Ctx) error {  
			// Redirect to Vite dev server  
			return c.Redirect("http://localhost:5173")  
		})  
	} else {  
		// Serve built assets in production  
		app.Use("/assets", filesystem.New(filesystem.Config{  
			Root: http.Dir("./dist/assets"),  
		}))  
		app.Get("/*", func(c *fiber.Ctx) error {  
			return c.SendFile("./dist/index.html")  
		})  
	}

Using Gin

if gin.Mode() == gin.DebugMode {  
        // Serve Vite in development  
        router.Use(func(c *gin.Context) {  
            if c.Request.URL.Path == "/" || strings.HasPrefix(c.Request.URL.Path, "/assets/") {  
                proxy := httputil.NewSingleHostReverseProxy(&url.URL{  
                    Scheme: "http",  
                    Host:   "localhost:5173",  
                })  
                proxy.ServeHTTP(c.Writer, c.Request)  
                return  
            }  
            c.Next()  
        })

        // Fallback route should be last  
        router.NoRoute(func(c *gin.Context) {  
            c.Redirect(http.StatusFound, "http://localhost:5173")  
        })  
    } else {  
        router.Use(static.Serve("/assets", static.LocalFile("./dist/assets", false)))  
        router.NoRoute(func(c *gin.Context) {  
            c.File("./dist/index.html")  
        })  
    }

Please create an account or sign in to leave a comment.

AI Won't Replace Writing

Tristan Isham
26 Nov 2024, 6:12 pm · edited

In his most recent essay, Paul Graham, founder of Y-Combinator, misses the forest for the trees in his prediction that writing as a skill will be functionally extinct because of AI. To be specific, Graham thinks that many people won’t be able to write because AI has dissipated almost all pressure to write. And because the gap between being a good writer and not being able to write has disappeared.

I want to presuppose that when he says writing, Graham means communicating effectively and asynchronously through text. Not actually writing by typing keys or scratching pens. I don’t think that skill will ever go away because frankly, using your voice alone to communicate would suck. It is not realistic in any litany of places where it would either be inappropriate, too loud, or impossible to talk.

In his essay, Graham says, “One of the strangest things you learn if you're a writer is how many people have trouble writing. Doctors know how many people have a mole they're worried about; people who are good at setting up computers know how many people aren't; writers know how many people need help writing.”

I’m more than willing to agree with that. When I was in journalism school, I was horrified that even after four years, seniors who had been coached for 1/5th of their lives on how to write could barely string together a succinct essay. I can’t imagine the quality of the average person’s paper today. To these people, writing well was never important, because if it had been, they’d have learned how to do it. They wrote well enough to pass their classes, and well enough to ease their minds. For them, using AI to write is like using spell check and accepting all changes. There was no craft to begin with. Yet, by the very nature of having to communicate with the AI, and that I can’t imagine a world in which not being able to write without using an AI doesn’t get you teased out of the room, I imagine that even these people will retain a poor to okay level of writing skill.

Graham also talks about how “AI has blown this world open. Almost all pressure to write has dissipated. You can have AI [write] for you, both in school and at work.”

In school, if used unethically like when writing a paper, AI scribing is only going to result in more student suffering. No matter how advanced an AI becomes, it will never be able to write an essay by hand in a blue book with a number 2 pencil. I hate to say it, but kids are spoiled by Chromebooks and iPads. If kids are found to be cheating on their essays or on their online tests, there’s nothing stopping teachers from taking a step back from technology on test days and forcing students to write by hand. AI might be the revitalization handwriting needs.

Graham asks, “Isn't it common for skills to disappear when technology makes them obsolete? There aren't many blacksmiths left, and it doesn't seem to be a problem.” Yet only a paragraph later distinguishes writing from other skills by stating, “writing is thinking. In fact there's a kind of thinking that can only be done by writing. You can't make this point better than Leslie Lamport did: If you're thinking without writing, you only think you're thinking.”

People are still taught how to write by hand, and even cursive. The most popular medium for books is still paper, despite e-reader’s many advantages. We don’t operate in a reality where the rational choice is always the one that wins. Instead, emotions often rule our days, and writing is one skill unlike any other--inexplicably tied to our thoughts and feelings. I don’t see a world in which we ever let that skill go.

Please create an account or sign in to leave a comment.

braxton 3 Feb 2025, 4:15 pm

Another change to consider is the style and capabilities that have, and will continue to decline with the influx of AI. There's less self reliance for growth of newer writers who can easily turn to AI to have multiple versions of the works edited and rewritten. Why foster personal growth and knowledge when the option of ease and faster results is available with AI? I anticipate we see writing styles and capabilities decline with the increased use of AI writing tools.

My day starts slowly. A cup of coffee, a quick YouTube video, and I’m off to work. It’s not a long commute to my office in the other room, but by the time I’ve sat down my mind is already buzzing with a long list of tasks. Distractions like unfinished chores leftover from the week and new work for today. I find it hard to lock in on tasks I’m not personally interested in, or to stay focused for long bits of time. I tend to flutter between busywork until I find a single task to focus on, at which point I can stay targeted on that task for hours. I get my work done, but I wish I could still accomplish more.

I scarf down my dinners. Dieting habits aside, I’ve developed a propensity for being a fast eater. My fiancé tells me to slow down, but that never made much sense to me. Why slow down when I can finish it this fast? It never clicked until last night when I was drinking a protein shake. After finishing it in two gulps, she looked at me in loving horror and commented on how I could not have enjoyed that. I was confused. Of course, I enjoyed it. I drank it didn’t I? I thought it tasted great! But on later reflection, I realized what she meant. I hadn’t taken the time to process the drink. Instead of savoring it, remembering its flavor, and enjoying it, I had consumed it. I had missed the broader point of the drink by leaning too hard on what it could do for me functionally—fill me up and taste good.

If you asked me to describe the drink to you, I could say it was chocolaty, but not much more. I can’t remember the texture or viscosity. It is a faded and soon to be forgotten memory because I didn’t take the time to properly catalogue and enjoy it.

I’m going to work on treating more of my life like a chocolate protein shake. To be savored and understood, not to be rushed through. Like with books. I always have trouble remembering the names of characters in books. It doesn’t matter if I’ve just looked from the page. Their names stay down with the ink. Maybe, if I read books a little slower and with more care, I wouldn’t struggle to remember the cast of my stories? Simply, I’m so enamored with the concept of done, that I’ve sacrificed the art of doing.

Please create an account or sign in to leave a comment.

braxton 12 Dec 2024, 1:23 pm

There's beauty in the small things that you come to see with this mindset. Step away from your phone, separate your work and your life, the growth and change you will gain won't be hard to miss. You should check this out: https://improvisedlife.com/2021/10/19/kurt-vonnegut-we-are-here-on-earth-to-fart-around