I am trying to deploy a React app via cloud functions and I want to server the static files.
So basically the root of the structures are :
Build/ (which contain React built stuff)
index.js
In cloudbuild.yaml last section of deployment I am using handlers but it does not affect of static files
- name: "gcr.io/cloud-builders/gcloud"
handlers:
- url: /static
static_dir: build
- url: /.*
script: auto
args: ['functions','deploy','something',...]
What I guess is that the functions could not directly do such static files and we must put them in to a bucket. Any idea?
Related
I was able to preview the HTML page on cloud shell and it shows everything correctly. when i deploy the app using "gcloud app deploy", the display is not showing the same page display as the preview page. for the deployment view, a specific CSS file data was pulled. while the preview page pulled from another CSS file. I have 2 different CSS files. app.yaml appended here. please advise.
{
runtime: python37
runtime_config:
entrypoint: "gunicorn -b:$PORT main:app"
env: flex
python_version: 3
handlers:
-
static_dir: images
url: /images
-
static_dir: static/css
url: /css
-
static_dir: templates/css
url: /css
-
script: auto
url: /.*
Considering your app.yaml, indeed, it seems that your CSS files are not being ready while your application is deployed and run.
For this reason, I would recommend you to take a look at the articles CSS and multiple HTML files in App Engine and Loading Images and CSS in AppEngine, where you can find more information and assistance on configuring your App Engine to read and use the CSS file during the deployment.
Let me know if the information helped you!
I know the path directory is the right path, it's just that I always get the error 'Error: ENOENT: no such file or directory, stat '/public/resetp.html'
My paths are as follows:
index.js: firebase/functions/index.js
reset password.html: firebase/public/resetp.html
When I go to this endpoint on my function on my website it runs this code:
response.sendFile(path.join(__dirname, '/./public/resetp.html'));
I need to use the sendFile() function so that I can just render the html file and not change the URL since in the html file that I'm trying to load, it gets the parameters of the URL (like the action code) and gets the users input to reset the users password.
Thanks, Nathan
You can achieve this by making your public directory inside your functions directory:
{
"hosting": {"public": "functions/public"}
}
All of the files in your functions directory are deployed with Cloud Functions, and no files outside of it are available.
Warning: The files that will be available will be whatever files are in the public directory at the time you deploy Cloud Functions. It is up to you to make sure Hosting and functions deploys are kept in sync.
When I build a maven project from GitHub using Cloud Build (resulting in jar files in a bucket) I get an extra file uploaded to my bucket that specifies what files have been built (artifacts-[build-no].json). The file has a unique name for every build, so the bucket gets filled up with loads of unwanted files. Is there a way to disable the creation of that file?
I think the json is only generated when using the artifacts flag, such as:
artifacts:
objects:
location: 'gs://$PROJECT_ID/'
paths: ['hello']
You could manually push to a bucket in a step with the gsutil cloud builder, without the helper syntax. This would avoid the json creation.
https://github.com/GoogleCloudPlatform/cloud-builders/tree/master/gsutil
# Upload it into a GCS bucket.
- name: 'gcr.io/cloud-builders/gsutil'
args: ['cp', 'gopath/bin/hello', 'gs://$PROJECT_ID/hello']
I am trying to follow all the steps as according to this blog here to host a static website using google app engine. The app.yaml file looks like this:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: website/index.html
upload: website/index.html
- url: /
static_dir: website
Say my project ID is abcd-123. When I go to abcd-123.appspot.com, it's giving the 404 error. (Also, I am using the same folder they've provided for hosting). Please suggest what am I doing wrong?
Make sure that you have a website folder, and inside of it, you have index.html file, along with a self created app.yaml file. Also make sure that you mention your project id while running the set project command and not project name!
On my computer, I access my test webpage on URL http://127.0.0.1:4000. On server, it will be on GitHub pages, that means https://username.github.io/repo-name/.
In the _config.yml I see following relevant settings:
# Uncomment if you are planning to run the blog in a subdirectory
# Note - if you enable this, and attempt to view your site locally you have to use the baseurl in your local path.
# Example, you must use http://localhost:4000/path/to/blog
#baseurl: /path/to/blog
baseurl:
# The URL of your actual domain. This will be used to make absolute links in the RSS feed.
url: http://yourdomain.com/
So for GitHub server I need it to be:
baseurl: /repo-name/
url: https://username.github.io/
But on localhost, it must be:
baseurl:
url: http://127.0.0.1:4000
These settings are necessary because without them, I will get 404 errors for resources that are using relative paths:
<script src="js/ghapi.js"></script>
"NetworkError: 404 Not Found - http://127.0.0.1:4000/download/js/ghapi.js"
The path should be http://127.0.0.1:4000/js/ghapi.js but since the page was /download it was added to relative URL of the script file.
I need to deal with this issue, how do I do that?
The best solution was to have two config files. The additional one, debug.yml, overrides some settings from the basic one. Both setting files can be loaded using this command:
jekyll serve --config _config.yml,debug.yml
The debug file can contain:
name: MySite [DEBUG MODE]
debug: true
url: http://127.0.0.1:4000
The advantage here is that no setting files need to be changed, you just use different command to run jekyll.
For me the best option is having in config.yml the baseurl used in Github pages and when you launch your site locally, override this value with an empty one:
bundle exec jekyll serve --baseurl=
That way, the site will work on localhost and in ghpages.
you can add a branch and change url line in config.yml
url: http://127.0.0.1:4000