Missing jwtSecret. Please, set configuration variable "jwtSecret" in Strapi - heroku

Strapi Error
I am trying to deploy a Strapi app to Heroku. I have set APP_KEYS and JWT_SECRET config vars in Heroku. I have also added this code to plugins.js as stated in this question. But I am still getting this error (see image). Can anyone help with this?
const crypto = require("crypto");
module.exports = ({ env }) => ({
"users-permissions": {
config: {
jwtSecret: env("JWT_SECRET") || crypto.randomBytes(16).toString("base64"),
},
},
});

Related

'Invalid host header' when deploying when deploying to heroku

Because of the Access to XMLHttpRequest CORS policy I've had to create a proxy in my package.json folder to get around posting to an external API. However, when trying to deploy this to Heroku I am getting: Invalid Host header. I've setHOST=name.herokuapp.com in my .env.production as well as tried using middleware:
const { createProxyMiddleware } = require("http-proxy-middleware");
module.exports = function (app) {
app.use(
createProxyMiddleware(
["external_api/endurl"],
{
target: "externalapi/starturl",
}
)
);
};

Svelte Proxy with rollup?

I'm trying to proxy requests from a Svelte app to a different port, where my backend API runs. I want to use a rollup proxy in the dev environment.
I read the alternative of using a webpack proxy here, but I want to give rollup proxy a try.
This is not an issue in production.
As suggested, I tried configuring rollup-plugin-dev However, whenever I make a request to weatherforecast I still get an CORS error. Below is my configuration and the call:
import dev from 'rollup-plugin-dev'
// other code
export default {
input: 'src/main.js',
output: {
sourcemap: true,
format: 'iife',
name: 'app',
file: 'public/build/bundle.js'
},
plugins: [
dev({
proxy: [{ from: '/weatherforecast', to: 'https://localhost:7262' }]
}),
// other code
];
and App.svelte looks like this:
<script>
import { onMount } from "svelte";
const endpoint = "/weatherforecast";
onMount(async function () {
try {
const response = await fetch(endpoint);
const data = await response.json();
console.log(data);
} catch (error) {
console.log(error);
}
});
</script>
Any help in solving this issue is appreciated.
What's happening is the proxy is passing through the CORS headers un-touched, so you're basically interacting with the API as though the proxy wasn't even there, with respect to CORS.
I'll note that you can get around this in dev, but keep in mind this problem will come up in production too, so you may just need to rethink how you're getting this data.
For development though, you can use something like cors-anywhere. This is a middleware that you can run through your dev server that can rewrite the headers for you.
To configure rollup-proxy on dev environment, you need to remove the call to the serve method, call the dev method and move the proxy calls inside the dev method:
import dev from 'rollup-plugin-dev'
// other code
export default {
input: 'src/main.js',
output: {
// other code
commonjs(),
// enable the rollup-plugin-dev proxy
// call `npm run start` to start the server
// still supports hot reloading
!production && dev({
dirs: ['public'],
spa: 'public/index.html',
port: 5000,
proxy: [
{ from: '/weatherforecast', to: 'https://localhost:7262/weatherforecast' },
],
}),
// line below is no longer required
// !production && serve(),
// other code
];

Nextjs TypeError: "Cannot read property 'headers' of undefined", after update to nextjs 12.1.0

After update to Nextjs 12.1.0, when I call api via api route, the following error is returned. I'm using aws amplify.
The following error is returned in the CloudFront console:
My api route:
const handlerProducts = async (req: NextApiRequest, res:NextApiResponse) => {
const params = req.query;
try {
const { data } = await axios.get(URL, {
params,
});
res.status(200).send(data);
} catch (err: any) {
res.status(500).end();
}};
What could be causing this problem?
Thanks for all the help.
I downgraded next.js to 12.0.8 and it works again
While investigating possibly the same issue, I found https://github.com/serverless-nextjs/serverless-next.js/issues/2327
zhenjie states on GitHub: "Confirmed 12.0.8 works fine, and 12.0.9 does not work."

Not sure how to deploy puppeteer to heroku when using heroku to host a bot

I have a bot command which is an image scraper, and it uses puppeteer. I have the puppeteer files downloaded into my VSC(Visual Studio Code) and when I run the bot from the VSC terminal, the image scraper function works. I can commit the files that I use onto GitHub, which is then linked to Heroku. But when I try to host the bot on Heroku and use the image scraper command, Heroku gives UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process! I have also added the puppeteer buildpack to my heroku project as well, and that doesn't seem to fix the problem. One solution I've seen is adding { args: ['--no-sandbox'] } to the code, but I'm not sure where to add it. Where can I add the --no-sandbox, or is there another fix to this problem? Thanks
Image Scraper code:
var Scraper = require('images-scraper');
const google = new Scraper({
puppeteer: {
headless: true
}
})
module.exports = {
name: 'image',
description: 'sends img to channel',
async execute(client, message, args){
const image_query = args.join(' ');
let rng = Math.round(Math.random()*10)
if(!image_query) return message.channel.send('Unable to find image');
const image_results = await google.scrape(image_query, 100);
message.channel.send(image_results[rng].url);
}
}
Edit (for image-scraper)
You can use all puppeteer.launch options as normal, with the puppeteer option. You can do it like this.
const google = new Scraper({
puppeteer: {
headless: true,
args: ["--no-sandbox"],
},
});
You can read more about using image-scraper on Heroku here.
Previous (for puppeteer)
As you mentioned you can add --no-sandbox argument to your code like this.
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
],
});
You can read the puppeteer.launch documentation here.
If this doesn't help you, you should check out the official troubleshooting guide on running Puppeteer on Heroku.

express-stormpath request.uri is undefined

I'm trying to run express-stormpath on an aws linux instance that is successfully serving. I've double and tripled checked my keys and app hrefs and assured they were connected to applications. I've gone to a fresh vm and used the simplest service to ensure something wasn't awry in the VM where I am successfully serving a sailsjs app.
var express = require('express');
var stormpath = require('express-stormpath');
var app = express();
var stormpathInit = function(req,res,next) {
stormpath.init(app, {
apiKey: {
id:'##########',
secret: '############',
},
secretKey: 'theLongRoadToNowhere',
application: 'https://api.stormpath.com/v1/applications/###',
website: true,
api: true
});
next();
};
app.use(stormpathInit);
app.get('/', function (req, res) {
res.send('Login');
});
/* and this failed as well with the same output only on server startup
app.use(stormpath.init(app, {
apiKey: {
id:'4SL89BZ47ALZX6T9W7S4NPUXS',
secret: 's0dA33RPTAqcDAcdbwj6q9i0qDDEr0XyHhsBmjF34SY',
},
secretKey: 'theLongRoadToFreedomWillPayDividends',
application: 'https://api.stormpath.com/v1/applications/1wShCspJ1NFnT1N1UM1laJ',
website: true,
api: true
}));
*/
app.listen(1337);
///////////////////////
The error output:
req.uri = undefined
/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/RequestExecutor.js:70
throw new Error('request.uri field is required.');
^
Error: request.uri field is required.
at RequestExecutor.executeRequest [as execute] (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/RequestExecutor.js:70:13)
at doRequest (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/DataStore.js:277:27)
at onCacheResult (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/DataStore.js:301:5)
at Array.<anonymous> (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/cache/Cache.js:54:14)
at DisabledCache.get.DisabledCache.set.DisabledCache.delete.DisabledCache.clear.DisabledCache.size (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/cache/DisabledCache.js:11:62)
at Cache.get (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/cache/Cache.js:52:14)
at CacheHandler.getCachedResource [as get] (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/cache/CacheHandler.js:91:51)
at Object.executeRequest [as exec] (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/DataStore.js:294:22)
at DataStore.getResource (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/DataStore.js:122:16)
at Client.getResource (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/Client.js:313:38)
Any guidance is appreciated...
Unfortunately the answer from photon did not work for me, but after communicating with Stormpath support (which was very helpful) the following fixed my problem:
Set environment variable STORMPATH_APPLICATION_HREF by running this in the shell:
export STORMPATH_APPLICATION_HREF=<YourAppsHREF>
Hopefully this will work for others as well.
The problem seems to be a small typo in the stormpath documentation. They currently instruct you to set an environment variable called STORMPATH_CLIENT_APPLICATION_HREF. This is incorrect, it should be STORMPATH_APPLICATION_HREF as shown above.
I had the same problem and after looking at the current default options for the Stormpath middleware, changing the following line resolved my issue.
Before
application: 'https://api.stormpath.com/v1/applications/1wShCspJ1NFnT1N1UM1laJ'
After
application: {
href: 'https://api.stormpath.com/v1/applications/1wShCspJ1NFnT1N1UM1laJ'
}

Resources