App engine SDK not accessible in Gradle app engine project - google-app-engine

My build.gradle:
buildscript { // Configuration for building
repositories {
jcenter() // Bintray's repository - a fast Maven Central mirror & more
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' // latest App Engine Gradle tasks
}
}
repositories { // repositories for Jar's you access in your code
maven {
url 'https://maven-central.storage.googleapis.com' // Google's mirror of Maven Central
// url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT Repository (if needed)
}
jcenter()
mavenCentral()
maven {
url "s3://my.private.repo.com/maven/releases"
credentials(AwsCredentials) {
accessKey AWS_ACCESS_KEY
secretKey AWS_SECRET_KEY
}
}
}
apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
dependencies {
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
compile 'com.google.appengine:appengine:+'
compile 'com.stripe:stripe-java:3.6.0'
compile 'javax.mail:mailapi:1.4.3'
}
appengine { // App Engine tasks configuration
run { // local (dev_appserver) configuration (standard environments only)
port = 8080 // default
}
deploy { // deploy configuration
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}
group = 'com.example.appengine' // Generated output GroupId
version = '1.0-SNAPSHOT' // Version in generated output
sourceCompatibility = 1.7 // App Engine Standard uses Java 7
targetCompatibility = 1.7 // App Engine Standard uses Java 7
The Stripe and JavaMail JARs appear to be downloaded just fine. But when I run compileJava I get other errors:
/path/to/eclipse-workspaces/google-eclipse-projects/myproject/src/main/java/com/package/ChargeStripeServlet.java:3: error: package com.google.appengine.api.taskqueue.TaskOptions does not exist
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
...
It appears that the App Engine SDK is not being downloaded, but I don't see any error message. I have installed the SDK locally, if that helps (although I suspect the JARS will just be downloaded anyway).

What you need to do is to add the following dependency:
compile 'com.google.appengine:appengine-api-1.0-sdk:+'
As you can see here 'com.google.appengine:appengine:+' is of type POM, hence does not carry any java classes, it's only a parent.

Related

Deploy ASP.NET core 7 Web API with React front end

I wrote an ASP.NET Core 7 web API backend and standalone Javascript React front end. I can deploy the backend to IIS successfully and it works fine through postman. However when I try to deploy the react front end using the method described in this tutorial https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-asp-net-core-with-react?view=vs-2022
my visual studio just freaks out and crashes. I am trying to figure out how to deploy the front end manually without using the visual studio publish feature.
This is my project setup:
[1]: https://i.stack.imgur.com/cApdk.png
And this is the IIS side where the WEB API backend is currently published:
[2]: https://i.stack.imgur.com/GtJ9O.png
Do I need to create a separate site for the frontend or can I deploy it to the same site as the backend? How can I build the frontend and manually deploy to the IIS?
For the site to work properly, you should build the frontend part in production mode, i.e. use the command npm run build instead of npm run start.
And then move the resulting files to the wwwroot folder inside your NET7 project.
Additionally, you should add static files using the AddStaticFiles method.
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-7.0
Also remember to set the ports correctly, because you can have different ones in the development and production environment, you will do it in launchsetting.json
You just need to change your Program.cs file like below, the you could publish webapi project directly. Every step mentioned in the official document must be completed, and finally add the following code.
namespace WebApplication1
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
else
{
app.UseDefaultFiles();
//app.UseStaticFiles();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
//app.MapControllers();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
// Add this line
endpoints.MapFallbackToFile("/index.html");
});
app.Run();
}
}
}
Test Result

Unknown service worker is being registered

I am using the built in service worker found in create-react-app. I have registered it in index.tsx with serviceWorker.register();. If I create a production build and run it, or run it on heroku server, I successfully get a service worker registered. However, upon further inspection under the Application tab in the dev tools, I see service-worker.js as the name of my service worker, which is NOT what mine is called. Inspecting the worker, it is also very different code from that of the default create-react-app, the contents are below -
/**
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app and you should
* disable HTTP caching for this file too.
* See https://developers.google.com/web/tools/workbox/guides/service-worker-checklist
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
* See https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config
*/
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
importScripts(
"/precache-manifest.740fac3abc44b443a1d2c6ac9789a1e1.js"
);
self.addEventListener('message', (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});
workbox.core.clientsClaim();
/**
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://developers.google.com/web/tools/workbox/modules/workbox-precaching
*/
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
workbox.routing.registerNavigationRoute(workbox.precaching.getCacheKeyForURL("/index.html"), {
blacklist: [/^\/_/,/\/[^\/]+\.[^\/]+$/],
});
Meanwhile the create-react-app service worker should look like this.
I am wondering where this other service worker is coming from, and how can I make sure my own is registered instead?
I haven't read them both, but it seems like maybe yours was compiled/transpiled by webpack into that one.
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/package.json
That service worker cdn is workbox v4.3.1 which you can see in the above package.json is a dependency. It is then used in a webpack config file.
Typescript is a way to write JavaScript, but it needs to be changed to JavaScript before it can be run in most cases.
Edit: where it's used
https://github.com/facebook/create-react-app/blob/589b41aecaa10d410713794f66a648bf3a72fb62/packages/react-scripts/config/webpack.config.js#L674
https://create-react-app.dev/docs/making-a-progressive-web-app/
And in conclusion: serviceWorker.ts is not a service worker. It is used to register one. The one you see on Heroku? That is the service worker you registered for, create-react-app's default one.
In my case:
I was using react.js and create-react-app.
I adopted new service-worker.js in public/
and my problem was that when I used yarn build to build react app, my service-worker.js is replaced with above file you copied(workbox service worker)
So I just made new file (public/worker.js) and replace
const swUrl = "${process.env.PUBLIC_URL}/service-worker.js";
with
const swUrl = "${process.env.PUBLIC_URL}/worker.js";
in src/serviceWorker.js > register > window.addEventListener('load')
and finally I can register my own service worker to my app

NoClassDefFoundError: com/google/appengine/api/search/IndexSpec

I am using Google App Engine along with Google Datastore and Google Search Api as the backend solution for my App.
Everything has been working fine until 3 days ago when I made a small modification and deployed my code. Then I encountered issues as java.lang.NoClassDefFoundError: com/google/appengine/api/datastore/DatastoreService. I am pretty sure the change I made has nothing to do with this, so I read google document (https://cloud.google.com/appengine/docs/standard/java/datastore/) and find that I need to use Google Cloud Client Library instead of app engine apis. so I added following code in my gradle and started using Client Library for datastore.
implementation 'com.google.cloud:google-cloud-datastore:1.98.0'
But this only fix issue for datastore, the issue for search api still exist. For search, I followed document at https://cloud.google.com/appengine/docs/standard/java/search/ , and I cannot find the replacement solution for it with Google Cloud Client Library (as listed: https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients).
I also read the document for Google Api Client Library (https://developers.google.com/api-client-library/java/apis), also cannot find the solution.
my gradle file:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11"
}
}
version '1.0'
sourceCompatibility = 1.8
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
mavenCentral()
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile 'com.google.appengine:appengine-api-1.0-sdk:+'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
compile "org.jetbrains.kotlin:kotlin-stdlib:1.3.11"
compile 'com.google.code.gson:gson:2.8.2'
implementation 'com.google.cloud:google-cloud-datastore:1.98.0'
compile 'jstl:jstl:1.2'
}
appengine {
deploy { // deploy configuration
}
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

Heroku doesnt serve bundled React JS application in Spring Boot

I have the following gradle build configuration
node {
version = '10.14.2'
npmVersion = '6.5.0'
download = true
workDir = file("${project.buildDir}/node")
nodeModulesDir = file("${project.projectDir}/src/main/webapp/chronos-ui")
}
bootJar {
baseName = 'chronos'
version = '0.1.0'
from("${project.projectDir}/src/main/webapp/chronos-ui/build") {
into "${project.projectDir}/src/main/resources/static"
}
}
task installFeDependencie(type: NpmTask) {
args = ['install']
}
task buildFe(type: NpmTask) {
args = ['run-script', 'build']
}
buildFe.dependsOn(installFeDependencie)
build.dependsOn(buildFe)
Basically it does the following:
Builds ReactJS application
Copies the build ReactJS application into jar file
When I locally executegradlew build and then java -jar jar_name.jar
I am able to see the built React JS application at the localhost:8080
However, when I deploy my app to the heroku, the access to the root URI provides me 404 error.
What is the problem and how can I fix it?

Trying to serve CRA build folder statically in asp.net core 2

I created a basic web api, and added a react frontend using create-react-app. When in production I want to serve the build folder which gets created by running npm run build from create-react-app statically. Based on what I found on the docs here, I tried the following, but to no avail. I get a 404, and nothing on screen.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsProduction())
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "client/build")),
RequestPath = "/static"
});
}
app.UseMvc();
}
Not sure where I am going wrong.

Resources