Cannot write schema.gql to Google's App Engine at runtime NestJS - javascript

I am using NestJS and I am using their graphql package.
https://docs.nestjs.com/graphql
Nest Generates the schema.gql file at run time. This is causing an issue with google's App Engine because by default, applications can't write to the file system.
UnhandledPromiseRejectionWarning: Error: EROFS: read-only file system, open 'schema.gql'
I understand how this would be a problem for storing data on the file system, but this schema.gql file that is generated at runtime is nessecary for the app to run and doesn't matter if it gets replicated.
Is there a work around I am missing? Can I get this to generate serverside somehow? Or is there a way I could make it apart of compile time when the application builds?
Any help is appriciated :)

Shout out to the NestJS Discord where this question got answered by #TreeMan360!
Where you have:
autoSchemaFile
in your
GraphqQLModule.forRoot({...
set it to:
true
which gives you an automatic, in memory only, schema. I do this like so:
GraphQLModule.forRoot({
autoSchemaFile: isLocalEnvironment() ? 'api-public.schema.gql' : true,
playground: !isProductionEnvironment(), ...
Following these instructions solved my problem! Niffty huh?

Related

Check Production and Staging environment inside HTML file in a React App

I am trying to integrate a 3rd party app inside my React App. I have to use different keys for production and staging but I am unable to figure out how to achieve that in React and Node applications I can do it by process.env but in index.html I am unable to figure out how can I achieve that.
Here is my pseudocode which I am trying to pull for my index.html file for my React project
<script>
if(env === production){
some_app.init('TOKEN_FOR_PRODUCTION');
}
else{
some_app.init('TOKEN_FOR_STAGING_OR_DEV');
}
</script>
While I personally prefer to store all API keys on the server itself, this guide indicates that there are other ways to do it:
https://www.geeksforgeeks.org/how-to-hide-your-api-keys-from-public-in-reactjs/
Additionally, to define differences between prod and staging in the front end alone, I recommend defining plug in variables using webpack:
https://webpack.js.org/plugins/define-plugin/

How to access environment variables with vanilla javascript

I have an index.html and I need to pass some sensitive information to some JavaScript variables. This index.html contains plain javascript with jquery
so I am settning environmental variable like this:
USERNAME="123"
PASSWORD="password"
And I need to access this using javascript
<script>
var username = process.env.USERNAME;
var pw = process.env.PASSWORD;
</script>
but this gives the error
Uncaught ReferenceError: process is not defined
Maybe this is because I am using vanilla javascript. And I can't use any other framework other than jquery
Can someone help me how to do this?
I had this exact issue to deal with and I was able to create a working solution using this article. For this answer, I'll summarise the steps I took for a project deployed to Netlify and already modified to fit your question, but you can check out the article to see the base example and also learn more.
Note: This solution is ideal for small personal projects where the information is not exactly sensitive but you just don't want them
displayed so visibly in your code. Do not use for larger projects that require a reasonable level of security measures.
If your project is already deployed to Netlify, or a similar platform where you can add build/deploy commands:
Go to the build settings
If the script file you want to use the variables for is in a folder, set the build command to this: cd DIRECTORY-FOR-THE-SCRIPT-FILE && echo -e "export const USERNAME="123";\nexport const PASSWORD="password";" > config.js
If the script is in your root folder, set the command to this echo -e "export const USERNAME="123";\nexport const PASSWORD="password"; > config.js
In your index.html file where you import the script, set your script tag to include this attribute type="module" i.e <script src="./index.js" type="module"></script>
In your script file, import the variables by adding this line to the file: import {USERNAME, PASSWORD} from "./config.js"
Trigger a redeploy manually on Netlify, or it will be deployed automatically if you already set automatic deploys for the repo.
That's all!
This solved mine and I hope it helps anyone else✨.
So what is your environment? javascript runs in the frontend, where are you setting the env variable?
You may be able to use something like fs - https://www.npmjs.com/package/file-system to read from a file on the operating system, but I would not imagine most browsers would allow this

require is not defined at npm.js:2

Forgive me if this is something simple as my research has come up empty in regards to this specific issue. I am using Bootstrap the most recent release. I have noticed that there is a file that is new from previous releases called npm.js. I am hosting all the Bootstrap files locally on my hosted web server. I call the file like all the others in the head to the full path to the file. In the console I have this error.
npm.js:2 Uncaught ReferenceError: require is not defined
at npm.js:2
Which is referring to this line.
require('../../js/transition.js')`
Which is from this npm.js file that is in the newest Bootstrap
// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
require('../../js/transition.js')
require('../../js/alert.js')
require('../../js/button.js')
require('../../js/carousel.js')
require('../../js/collapse.js')
require('../../js/dropdown.js')
require('../../js/modal.js')
require('../../js/tooltip.js')
require('../../js/popover.js')
require('../../js/scrollspy.js')
require('../../js/tab.js')
require('../../js/affix.js')
I am unfamilar with this so I am not sure why I am getting this error but, how can I surpress this error and fix this issue? Do I even need this file? From what I understand if I am using modals or tooltips etc I need this. Is this correct?
You will need to download/config the missing libraries or requires. I am not sure which libraries you are using.
You can add the missing libraries to your package.json. Then call for npm install.

jarsigner: unable to sign jar: java.util.zip.ZipException: duplicate entry: org/appcelerator/titanium/gen/bindings.json

I am facing issue while using custom module in titanium application:-
[ERROR] : Failed to sign apk:
[ERROR] : jarsigner: unable to sign jar: java.util.zip.ZipException: duplicate entry: org/appcelerator/titanium/gen/bindings.json
I have created new custom module for android and I am trying to use this module in my application but at run time I am getting above error.
I didn't get any solution yet please share if anyone have any idea related to this issue.
Thanks
Long discussion regarding this error on the Appc JIRA (https://jira.appcelerator.org/browse/TIMOB-23502)
From the PR (https://github.com/appcelerator/titanium_mobile/pull/8551) looks like you will have to wait until 6.1.0 for the fix, or build a new sdk from master, or cherry pick the fixes into your current SDK.
In the discussion, Sean Conway offered a solution (https://jira.appcelerator.org/browse/TIMOB-23502?focusedCommentId=393172&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-393172) that worked for some folks, but not others.
I was able to remove the gen/bindings.json file by doing the following:
(1) Set Java Compiler to 1.8
(2) Update build.properties:
titanium.platform=/Users/xxx/Library/Application Support/Titanium/mobilesdk/osx/5.4.0.GA/android
android.platform=/Users/xxx/Library/android-sdk-macosx/platforms/android-23
android.ndk=/Users/xxx/android-sdks/build-tools/22.0.1/android-ndk-r10e
(3) Change all libraries in build path to use 5.4.0.GA JARS
(4) Delete build and dist folders then rebuild using ANT *** WIll not work otherwise, still produces gen file if you package-->android module
DO not use package option to build, go to build.xml, right click-->Run as Ant Build
Successful project build

Meteor + flowtype

I was playing around with all tools/technics I know to try to make Meteor and Flowtype to be friends. I made a meteor package to run flowtype checker as a linter. It works, but brings more troubles than help to my project so far. The problem is that flow does not have an easy way to declare all global libs interfaces, so when it checks my code, it of cause does not know anything about Meteor or Session global variables. Do I have to convert all Meteor API to an interface for Flow?
It also has troubles to understand the way we use to define global vars in Meteor.
Have anybody tried to fix this issues and how?
What you need is an interface file.
You need to do the following:
Declare the .flowconfig file (it's automatically created when you run flow init).
Create a folder to store your interface files that is ignored by Meteor so it doesn't try to parse it. Meteor ignores certain folder patterns, so you could try mkdir .interfaces. Add the folder to the [libs] section of your .flowconfig, comme ça:
[libs]
.interfaces/
Inside, you can create declarations for your global modules. To create one for Meteor, you can try to touch .interfaces/meteor.js and write something along these lines:
declare class Meteor {
isClient: boolean;
}
Let me know if that works. Still learning flowtype myself.

Categories

Resources