Error:The connection to the server was unsuccessfull(fake) in Angularjs App - angularjs

I am creating an angular app with Intel XDK.I have data on local storage.when I run the app in offline a message will appear after few minutes like "Application error:The connection to the server was unsuccessful(fake)" and stop the application spontaneously.how to manage this.I expect a hopeful solution to recover this.
app.js
$scope.checkConnection=function() {
var networkState = navigator.connection.type;
if(networkState == Connection.NONE){
$scope.footer_message = "No Network Connection";
return false;
}else{
$scope.footer_message = "Obidos Technologies (P) Ltd";
return true;
}
}
$scope.checkConnection();

If you are seeing inconsistent/transient error messages saying something like [Connection to server was unsuccessful to “www/assets/index.html”] when starting up your app. This is caused by your App timing out. You can either increase the time-out time, but will only reduce the frequency of the issue, or you can:
1.Rename your index.html to “main.html”
2.Create a new “index.html” and put the following content into it:
<!doctype html>
<html>
<head>
<title>tittle</title>
<script>
window.location='./main.html';
</script>
<body>
</body>
</html>
3.Rebuild your app! No more errors!

Related

How do I locate the discode widget bot?

When I run it on my local server, the widget bot comes out well. However, after distribution, the location is set as shown in the picture below.
What's the problem?
enter image description here
This is my code
<script
src="https://cdn.jsdelivr.net/npm/#widgetbot/crate#3"
async="true"
defer="true"
type="text/javascript"
>
new Crate({
server: '1066208369901322371',
channel: '1067308918826598501',
location: ['bottom', 'right']
})
</script>
Is there a problem with the environment variable you are deploying?

Removing .html from end of url in javalin

I'm using Javalin to serve my static web pages, which I've never done before. I know it's possible in Nginx to remove the .html from the end of your url but still route to the correct page, for example mysite.com/login would replace mysite.com/login.html but still point towards my login.html file. Is this possible in Javalin?
I've tried looking into the config (StaticFileConfig) but couldn't seem to find anything that would solve this problem
Here are two examples of what was discussed in the comments to the question, for future visitors:
The first example assumes there is a simple HTML file in the application's resources/html folder.
The test.html file:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>Hello world.</div>
</body>
</html>
The /test handler:
public static void main(String[] args) {
Javalin.create(config -> {
})
.get("/test", ctx -> {
ctx.contentType(ContentType.TEXT_HTML);
InputStream in = App.class.getResourceAsStream("/html/test.html");
ctx.result(in);
})
.start(8080);
}
If you choose to configure Javalin with Thymeleaf, and if you place your HTML file in the default location expected by Thymeleaf (resources/thymeleaf), then you can do this:
.get("/test", ctx -> {
Map<String, Object> model = new HashMap<>();
ctx.render("test.html", model);
})
In this case, the model used by Thymeleaf for rendering is empty because you don't need to make any substitutions in your HTML file (it's not a template). But it's a short step from this to using dynamic Thymeleaf templates.
I followed what andrewJames was saying and that worked for me. I was hoping there would be a cleaner way of doing this, as I'm just copy pasting the same code for every endpoint and changing the file path, but this works.

Data file location relative to html when running Azure Maps tutorials locally - atlas.io.read()

Trying to determine how to revise the atlas.ioread() function from the Azure Maps tutorial below to read the data locally on my windows machine.
atlas.io.read(window.location.origin + '/Common/data/Gpx/Route66Attractions.xml')
Does the 'window.location.origins +' work with local files?
I have nested the .xml file similarly to the above string, relative to the html file, however, it does reading the file when the map is launched.
Azure Maps Tutorial:
https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/master/AzureMapsCodeSamples/Spatial%20IO%20Module/Load%20spatial%20data%20(simple).html
That function won't be able to access local files directly as the URL must be a http or https URL. There are a couple of approaches you can take.
If you plan to host the file later, you can host it locally on localhost and then have a URL pointing to it.
If you want to access local files, you will first need to load the file into your app using the file input tag and the FileReader class. Once you have the raw file data (text), you can pass that into the atlas.io.read function and it will process if for you. Here is a simple example:
<!DOCTYPE html>
<html>
<head>
<title>Read Text File</title>
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.css" type="text/css" />
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.js"></script>
<!-- Add reference to the Azure Maps Spatial IO module. -->
<script src="https://atlas.microsoft.com/sdk/javascript/spatial/0/atlas-spatial.min.js"></script>
</head>
<body>
<input type="file" name="inputfile" id="inputfile">
<script type="text/javascript">
window.onload = function() {
var input = document.getElementById('inputfile');
input.addEventListener('change', function() {
var fr = new FileReader();
fr.onload = function(){
atlas.io.read(fr.result).then(function(r){
//r is the parsed data. Do something with it.
});
}
fr.readAsText(input.files[0]);
});
});
</script>
</body>
</html>

Unit testing in Kotlin JS

I have a simple project in Kotlin JavaScript using React. I've added unit tests, but when I run them, they seem to call main method of production code, and fail on initialization, when trying to reach unexsistent DOM structure. Despite the fact that the tested class does not reference React or DOM in any way.
The error looks the same when run from Intelij IDEA or by gradlew build (I've replaced the full path to my project with /APP/ for clarity):
Testing started at 17:51 ...
> Task :cleanBrowserTest
> Task :packageJson UP-TO-DATE
> Task :testPackageJson UP-TO-DATE
> Task :kotlinNodeJsSetup SKIPPED
> Task :kotlinNpmInstall
> Task :compileKotlinJs
> Task :processResources
> Task :mainClasses
> Task :compileTestKotlinJs
> Task :testProcessResources NO-SOURCE
> Task :testClasses
> Task :browserTest
(...)
Error: Target container is not a DOM element.
at render (http://localhost:9876/absoluteD:/APP/build/js/packages/example-test/adapter-browser.js?92ccabfdcfa982960828b65b2f4e2683080859b4:25359:13)
at render_0 (http://localhost:9876/absoluteD:/APP/build/js/packages/example-test/adapter-browser.js?92ccabfdcfa982960828b65b2f4e2683080859b4:29868:5)
at main (http://localhost:9876/absoluteD:/APP/build/js/packages/example-test/adapter-browser.js?92ccabfdcfa982960828b65b2f4e2683080859b4:146311:5)
at Object.<anonymous> (http://localhost:9876/absoluteD:/APP/build/js/packages/example-test/adapter-browser.js?92ccabfdcfa982960828b65b2f4e2683080859b4:146315:3)
at http://localhost:9876/absoluteD:/APP/build/js/packages/example-test/adapter-browser.js?92ccabfdcfa982960828b65b2f4e2683080859b4:146289:37
at Object.../example/kotlin/example.js (http://localhost:9876/absoluteD:/APP/build/js/packages/example-test/adapter-browser.js?92ccabfdcfa982960828b65b2f4e2683080859b4:146292:2)
at __webpack_require__ (http://localhost:9876/absoluteD:/APP/build/js/packages/example-test/adapter-browser.js?92ccabfdcfa982960828b65b2f4e2683080859b4:20:30)
at http://localhost:9876/absoluteD:/APP/build/js/packages/example-test/adapter-browser.js?92ccabfdcfa982960828b65b2f4e2683080859b4:146346:134
at Object../kotlin/example-test.js (http://localhost:9876/absoluteD:/APP/build/js/packages/example-test/adapter-browser.js?92ccabfdcfa982960828b65b2f4e2683080859b4:146351:2)
at __webpack_require__ (http://localhost:9876/absoluteD:/APP/build/js/packages/example-test/adapter-browser.js?92ccabfdcfa982960828b65b2f4e2683080859b4:20:30)
HeadlessChrome 81.0.4044 (Windows 10.0.0) ERROR
Uncaught Error: Target container is not a DOM element.
at d:/APP/build/js/node_modules/react-dom/cjs/react-dom.development.js:24828:1 <- D:/APP/build/js/packages/example-test/adapter-browser.js:25359:7
(...)
> Task :browserTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':browserTest'.
> command 'C:\Users\Arsen\.gradle\nodejs\node-v12.14.0-win-x64\node.exe' exited with errors (exit code: 1)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 10s
8 actionable tasks: 6 executed, 2 up-to-date
Minimal example:
./build.gradle.kts
plugins {
id("org.jetbrains.kotlin.js") version "1.3.70-eap-184"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") }
maven("https://kotlin.bintray.com/kotlin-js-wrappers/")
mavenCentral()
jcenter()
}
dependencies {
implementation(kotlin("stdlib-js"))
implementation("org.jetbrains:kotlin-react:16.13.0-pre.94-kotlin-1.3.70")
implementation("org.jetbrains:kotlin-react-dom:16.13.0-pre.94-kotlin-1.3.70")
implementation(npm("react", "16.13.1"))
implementation(npm("react-dom", "16.13.1"))
testImplementation(kotlin("test-js"))
}
kotlin.target.browser {
}
./settings.gradle.kts
pluginManagement {
repositories {
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") }
mavenCentral()
maven { setUrl("https://plugins.gradle.org/m2/") }
}
}
rootProject.name = "example"
./src/main/resources/index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="root"></div>
<script src="example.js"></script>
</body>
</html>
./src/main/kotlin/Main.kt
import react.dom.*
import kotlin.browser.document
fun main(args: Array<String>) {
render(document.getElementById("root")) {
}
}
./src/main/kotlin/DummyClass.kt
class DummyClass {
fun foo(): String {
return "foo"
}
}
./src/test/kotlin/ExampleTest.kt
import kotlin.test.*
class ExampleTest {
#Test
fun foo() {
assertEquals(DummyClass().foo(), "foo")
}
}
The error does not occur if I don't reference production code at all (remove DummyClass().foo() from the test), or when main method does not call render(document.getElementById("root")).
PS: If it matters I run the code on Windows
This is not the right answer - but something that will unblock you immediately.
This answer pointed out that
the test environment doesn't supply the DOM with an app id.
So too is the case with our test framework - it is not supplying an element with id 'root'.
This led me to believe that the main/resources/index.html is not being used by the test framework. The exception trace confirms that - notice how it starts from __webpack_require__
The ideal solution would be to either have karma or webpack supply our code with the correct index.html; but I don't know how to accomplish that.
In the meantime, you can
Remove <div id="root"></div> as part of index.html
Have your kotlin code generate it, as below:
./src/main/kotlin/Main.kt
fun main(args: Array<String>) {
document.body!!.insertAdjacentHTML("afterbegin", "<div id='root'></div>" )
render(document.getElementById("root")) {
}
}
Hope that helps
I had the same issue and I fixed it. Thanks to the workaround of #Yogesh Nachnani I understood what was missing. In fact all resources files are not included. So, first I created a new workaround using fs-extra (copying files from resources to the local directory) and then as I was exploring Karma I figured out that the cleanest solution was to use proxies to redirect requests to resources. Therefore I used the following code into karma.config.js:
const path = require('path');
const resourcesSourcePath = path.resolve(__dirname, '../../../../build/processedResources/js/main');
const setupFile = path.resolve(__dirname, '../../../../src/test/setup.js');
config.files.unshift(setupFile);
config.proxies = {
"/strings/": "absolute" + resourcesSourcePath + "/strings/",
"/css/": "absolute" + resourcesSourcePath + "/css/",
"/images/": "absolute" + resourcesSourcePath + "/images/"
}
This way, if you have a lot of resources you won't have to wait for the copy of the content. However, I didn't find a way to launch karma on index.html, but as I can now access all resources, I just used the workaround proposed by #Yogesh Nachnani because the HTML file usually doesn't have much influence into tests (at least for me). Therefore I added a setup.js file which only contains:
document.body.insertAdjacentHTML('afterbegin', "<div id='root'></div>");
It prevents the rendering target error when you are using render(document.getElementById("root")){} for React.

Is there any "serverless" / global database hosting?

I am bulling a little python + GTK app.
I need a way where I can store some index data on a server.
First I looked at RedHat´s OpenShift as the server rest-backend (python + flask + mysql)
But now I am thinking is there a way to just put some data into the "cloud".
I know the cloud just I a buzz word for other peoples computers / servers.
But something like the bitcoin where you just push some key/val data then any node in the network gets the data after some time.
Apache Cassandra look like can do some thing like this.
But I don't want to host anything.
Some thing like this.
$ datacloud <openid> <password> <databucket>
$ datacloud add <key> <jsondata / val>
$ datacloud get <key>
$ <jsondata>
Or in python.
import datacloud as dc
import json
def main():
dc.connect("<myopenid.provider.org>", "<password>", "<databucket>")
ds.add("key", json.dumps({"hello":"world"}))
for data in dc:
print data
print dc.get("<key>")
--> { "hello": "world"}
Or better just with jQuery.
<html>
<head>
<script href="pathto/jquery.js"></script>
<title>ServerLess / local site</title>
<script>
$(function(){
$.ajax({
url: "magnet:?xt=urn:btih:5dee65101db281ac9c46344cd6b175cdcad53426",
data: {
"openid": "<openid.myopenidprovier.org>",
"password": "<12345>",
"bucket": "<databucket>"
}
}).done(function(keys){
for(var i=0; i < keys.length; i++)
$('#news').append('<h3>'+key[i]+'</h3>');
});
});
</script
</head>
<body>
<h1>News with no server</h1>
<div id="news"></div>
</body>
</html>
I am looking for an p2p global key/val store.
... an freenet like data global key/val cache or store..
Update: the idea base on #SLaks comments.
<html>
<head>
<script href="pathto/jquery.js"></script>
<title>ServerLess / local site</title>
<script>
$(function(){
$.ajax({
url: "magnet:?xt=urn:btih:5dee65101db281ac9c46344cd6b175cdcad53426",
data: {
"pubkey": "<id_rsa.pub>",
"bucket": "<databucket>"
}
}).done(function(keys){
for(var i=0; i < keys.length; i++)
$('#news').append('<h3>'+key[i]+'</h3>');
});
});
</script
</head>
<body>
<h1>News with no server</h1>
<div id="news"></div>
</body>
</html>
Use ssh-keygen -t rsa
So only the admin can add data.
Um, no. A P2P network without commercial interest will not host your database for free.
So, you really just need a minimal database storage? You can buy that from multiple places. Look at the overly known Amazon AWS stuff. I'm sure you can rent database VM instances, too, or directly use the Amazon relational database service. I think for your "nearly no users, nearly no data" thing, a simple VM with a secure preconfigured database that you can only connect to through SSH or some VPN will probably be the most cost-effective solution.
However, it sounds like you'd quickly whip up a webservice, which would allow you to authenticate simple HTTPS clients securely, and then ask for / store the data of your application through that. That way, you can also solve the dilemma of not sharing your credentials with others.

Resources