CherryPy server static files without specific config file - static

I dont want a config file only for cherrypy. I need it only for a very smallish webserver which wont be actually accesible to the world, so no need for me to mock around in config files.
Is there a way to pass a "config" to wsgiserver when starting it? I just need a 5-10 line script to fire of a threading web server, which can run a flask application and server static files.
Also, I dont want to specify full path to the static files, just ./static from where the script is ran.

According to Changing default url to static-media in Flask the only option is to map /static to something that serves from os.getcwd() + '/static'.
Or with CherryPy: How to use cherrypy as a web server for static files?

Related

How to store API URLs in a files like app.config/web.config for a React app hosted in AWS S3

WHAT IS THE PROBLEM?
I have a React app hosted in AWS S3. The app makes a request to an API URL and displays the result. The API URL changes based on the environment.
DEV environment - https://192.168.0.1/api/users
TEST environment - https://192.168.0.2/api/users
I want to have these different API URLs in a file like app.config/web.config so that I can change the URL anytime I wanted (thus avoiding building/deploying).
WHAT HAVE I TRIED?
I tried adding these URLs in .env file as follows:
DEV_API_URL = https://192.168.0.1/api/users
TEST_API_URL = https://192.168.0.2/api/users
After this, I am able to consume these URLs from the React code as follows:
env.DEV_API_URL
env.TEST_API_URL
However, if I want to have these URLs changed, I should edit the .env file, build and deploy using Jenkins on every change.
The other method I tried was, to have these URLs as environment variables in Jenkins. In this method also, I need to build and deploy on every change
WHAT I NEED?
Could you let me know a place (like app.config/web.config) where I can change these URLS and my React app pick it up immediately without build/deploy?
You could store the URL in a database, and fetch the URL each time you need to reference the value in React.
It adds a lot of DB overhead, but it won't require any deployment. You just change the url in the DB as needed.
I think that you might want to use environment variables. Basically, you can build something for development / staging / production and have files named .env.development .env.production where you can have environment variables, like: REACT_APP_API_URL=https://example.com and use it in your code with process.env.REACT_APP_API_URL. Please note that they should be prefixed with REACT_APP.
Some libraries that you might use are: dotenv, env-cmd

Use a remotely rendered page instead of /public/index.html

I wonder if its possible to insteady relying on the source code of the file stored in /public/index.html one can use a remotely generated page to be used as the template for the dev server of create-react-app.
The point is that I'd like to take a page that contains data that is generated by the server and have my react app running in there for development purpose.
As far as I understand, the webpack dev server loads the file from the HDD upon request, modifies the content and delivers it to the browser. So technically it shouldnt be a problem to retrieve the source from a remote URL instead of the local hard drive, right?

How do I store the private key of my server in google app engine?

I'm using "github.com/dgrijalva/jwt-go" to create JSON web tokens.
When I hosted my server locally, I could use my private key as usual. But in GAE it won't work because I don't have access to the file system.
How would you guys do it? Store the key in datastore or any other ideas?
Thanks
Edit:
My app.yaml looks like this (below api_version and stuff):
handlers:
- url: /.*
script: _go_app
On AppEngine you don't have access to the file system of the host operating system, but you can access files of your web application (you have read-only permission, you can't change them and you can't create new files in the app's folder).
So the question is: do you want to change this private key from your application without redeploying your app? Or it is perfectly fine if it is deployed "statically" with your app's code?
If you don't need to change it (or only when you redeploy your app), easiest is to store it as a "static" file as part of your webapp. You may refer to files of your app using relative paths, where the current or working directory is your app's root. E.g. if your app contains a key folder in its root (where app.yaml resides), and there is a my_key.txt file inside the key folder, you can refer to it with the path: key/my_key.txt.
Actually it is quite common to "ship" static files with your app's code: just think of HTML templates which are read and processed by the Go code (e.g. package html/template) to produce HTML result; the content of the HTML template files are not served directly to clients.
If you need to change it from time to time without having to redeploy your app, then store it in the Datastore which your app can read and modify.
Note:
One important note: not every file is readable by code, this depends on the app configuration. Quoting from Configuring with app.yaml / Static file handlers:
Static files are files to be served directly to the user for a given URL, such as images, CSS stylesheets, or JavaScript source files. Static file handlers describe which files in the application directory are static files, and which URLs serve them.
For efficiency, App Engine stores and serves static files separately from application files. Static files are not available in the application's file system. If you have data files that need to be read by the application code, the data files must be application files, and must not be matched by a static file pattern.
Static file handlers can be defined in two ways: as a directory structure of static files that maps to a URL path, or as a pattern that maps URLs to specific files.
Read the link how to properly configure application and static files / directories.
The solution was to leave app.yaml as it were. Put app.yaml at root lvl in project. Then change all imports from starting at GOPATH to start at project root instead. The problem that made me choose to put app.yaml and main go file in a different folder under project root was because of double imports. Read this for a better understanding: Google Go AppEngine imports and conflicts when serving / testing
The solution made my project find the files I wanted.

GAE Yaml handler to use URLS

I have configured a bucket and to access the files uploaded here what should be the Yaml handler statement?
For example: http://commondatastorage.googleapis.com/yii2assets/e896c38e/css/bootstrap.css
When I browse this CSS file it prompts to download and looks it doesn’t understand the MIME type.
I can’t provide a static directory since it’s hosted on Google Storage and to access I need to use the URL mentioned above.
Please let me if you have any IDEAS.
What I need is a handle like:
url: bootstrap.css
script : URL FROM where TO SERVER
Like if I have to use a JQuery CDN URL.
You can upload static file with your code then config Yaml with static_files please see in doc.
If you want to upload file to Google Storage you can access by sending parameter from python to html file. It depend how you implement it Java, Python have a difference way to implement this.

nginX custom HTTP authorization , using scripts to decide

i want to protect some files in a folder by requiring passwords for download
however list of users that are allowed to download are on a mysql table with their passwords in md5 format (which means i cannot generate a htpasswd file)
to make it harder i also need to allow some users to download some files and others to download other files without being able to move files (separating files in multiple folders)
so i what i need is some kind of auth api , when there is a request nginx askes a Script (lets say a php script) with parameters of username/password/ip/filename and depending on script's response allow or disallow the download
is this possible?
what i've done so far:
1.looking in the 3rd party modules list http://wiki.nginx.org/3rdPartyModules
where i found a module with PAM but my server is windows
2.googling lots of terms without any results
3.looking at the module development tutorials http://www.evanmiller.org/nginx-modules-guide.html
i'm not really good at C so a pre made module for windows that bounces the request to a script (without proxy-ing the download through it) is the best if not some pointers to how should i make a module that meets my requirements is appreciated .
You can use the http_auth_request module.
p.s. Do you actually know that nginx for windows is not production ready?

Resources