Details of static website server configuration ( "hello-webpage" template)

#1

I’ve started development of a website on Glitch using the “hello-webpage” template, but I’d like to explore additional options for developing in external apps and importing my files ( such as importing from git ).

I might also try testing out updates on a local environment prior to pushing updates to Glitch.

Where can I get more information about the configuration of the server used by the “hello-webpage” template? I’d like to see what I would need to configure a local instance of node to behave the same as my Glitch app.

Thanks!

#2

Hey @dnrtc, welcome to the Glitch forum!

The hello-webpage project relies on the lws package for its web server and supports the configuration explained in https://github.com/lwsjs/local-web-server/wiki. If you look at the files in /opt/watcher/app-types/static/ you can see how we start up the web server.

Hope this helps, and if not let me know what else you’d like to know.

1 Like
Default Glitch Page
#3

From your description, this sounds like a complete answer! If I run into any snags when I try to put this into action, I may be back with more questions.

Thanks very much for the quick and detailed response!

1 Like
#4

Hi @cori!

I have a question and I hope it’s relevant enough to my original question to justify reusing the orignal thread instead of opening a new thread.

I’m reading up on lws and I’m wondering how I might be able to add my own server-side scripts.

I’m thinking pretty basic stuff at this point. I don’t want to run some script on every incoming HTTP request. (it seems like the “middleware” documentation describes that) What I have in mind is a script that has its own unique URL and when it is requested it is run on the server as opposed to the source file simply being served up.

It seems to me like this would be something common, but I haven’t yet encountered the documentation for it and I just don’t know how to distill this long story down to a few keywords to type into Google.

Do you have any suggestions of any resources that would help me out?

Many thanks!

#5

Hey @dnrtc I think the closest thing you could do is follow the Mocking pattern the LWS folks talk about at https://github.com/lwsjs/local-web-server/wiki/How-to-create-a-mock-response. That would enable you to define a module that executes specific Node code when specific routes are configured. I haven’t worked with defining the mocks parameter in configuration, but I think it should be doable.

That said, I’m curious why you’d want to do this instead of using something more designed for the purpose of running code on requests, like adding the routes you want to use in an Express app.

#6

This is my first excuse to really get my hands dirty with Node. I have years of experience with JavaScript on the client-side, but I’ve always used different stacks on the back-end. As a result, I’m thinking through this in a way that makes sense to me, but ultimately I might be doing things the hard way because I just don’t know better yet.

Lots of questions are coming to mind about using Express ( “do I have to write logic for routing of all incoming requests?” ) but I probably should spend some more time reading up and see how many questions I can answer for myself.

Thanks again for the assist!

1 Like
#7

I still want to make good on my previous comment where I said I needed to study Express more, but I realized that I omitted some information about what I wanted to accomplish.

In the lws documentation that describes the module for URL Rewriting, at the very bottom of the page there is an example of config code:

module.exports = {
  rewrite: [
    { from: "/broken/*", "to": "http://localhost:9999" },
  ]
}

(This I’ve trimmed this down to attract attention to a single line. I can’t do boldface in a code block)

I forgot to state this earlier, but I was looking to use the URL Rewrite module to route only certain URLs to scripts and all remaining routes could be served statically. I think that maybe this syntax including the localhost:[port] could be my answer. I’ll need to give it a try.

Should this not work out for me, I’ll be investigating how this is accomplished in Express.

Thanks again!

#8

I think (but have not tested) that if you want to do this with lws you’ll want to take a look at the Mock documentation I previously linked to, which allows for individual routes to execute the specified code. I’m fairly certain that the redirects will send an appropriate 301 / 302 HTTP status code with the new location, and won’t trigger any scripts to run.