Nuxt Heroku what to fill baseurl for it to run? - heroku

This is my nuxt.config.js file
env: {
baseUrl: process.env.BASE_URL || "http://localhost:3000"
},
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {
baseURL: process.env.baseUrl,
browserBaseURL: "http://localhost:3000"
},
Heroku logs
Listening on: http://localhost:21411/
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch.
What's env variable I need to add to heroku admin for it to work, the port heroku is hosting on keeps changing each time I try to run it.
EDIT here is my Nuxt config:
export default {
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
script: [
{
type: "text/javascript",
charset: "UTF-8",
src: "https://js.api.here.com/v3/3.1/mapsjs-core.js"
},
{
type: "text/javascript",
charset: "UTF-8",
src: "https://js.api.here.com/v3/3.1/mapsjs-service.js"
},
{
type: "text/javascript",
charset: "UTF-8",
src: "https://js.api.here.com/v3/3.1/mapsjs-mapevents.js"
},
{
type: "text/javascript",
charset: "UTF-8",
src: "https://js.api.here.com/v3/3.1/mapsjs-ui.js"
},
{
type: "text/javascript",
charset: "UTF-8",
src: "https://js.api.here.com/v3/3.1/mapsjs-clustering.js"
},
{
type: "text/javascript",
charset: "UTF-8",
src: "https://js.api.here.com/v3/3.1/mapsjs-data.js"
}
],
title: "Restaurants-D-System",
htmlAttrs: {
lang: "en"
},
meta: [
{ charset: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{ hid: "description", name: "description", content: "" }
],
link: [
{
rel: "stylesheet",
type: "text/css",
href: "https://js.api.here.com/v3/3.1/mapsjs-ui.css"
},
{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" },
{
rel: "preconnect",
href: "https://fonts.gstatic.com",
href: "https://fonts.googleapis.com/css2?family=Roboto&display=swap",
rel: "stylesheet"
},
{
rel: "preconnect",
href: "https://fonts.gstatic.com",
href: "https://fonts.googleapis.com/css2?family=Ribeye&display=swap",
rel: "stylesheet"
}
]
},
// Global CSS: https://go.nuxtjs.dev/config-css
CSS: ["~/assets/normalize.css"],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [],
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
"#nuxtjs/style-resources",
// https://go.nuxtjs.dev/buefy
"nuxt-buefy",
// https://go.nuxtjs.dev/axios
"#nuxtjs/axios"
],
styleResources: {
scss: ["./assets/main.scss"],
CSS: ["./assets/normalize.css"]
},
axios: {
baseURL: "http://localhost:4000" // Used as fallback if no runtime config is provided
},
publicRuntimeConfig: {
axios: {
browserBaseURL: process.env.BROWSER_BASE_URL
}
},
privateRuntimeConfig: {
axios: {
baseURL: process.env.BASE_URL
}
},
serverMiddleware: [{ path: "/api", handler: "~/api/index.js" }],
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {}
};
and here is my json:
{
"version": "1.0.0",
"engines": {
"node": "14.16.1"
},
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {
"#nuxtjs/axios": "^5.13.1",
"#nuxtjs/style-resources": "^1.0.0",
"#vonage/server-sdk": "^2.10.8",
"core-js": "^3.9.1",
"express": "^4.17.1",
"firebase-admin": "^9.8.0",
"infobip-nodejs": "^0.1.0-alpha.1",
"lodash.debounce": "^4.0.8",
"normalize.css": "^8.0.1",
"nuxt": "^2.2.0",
"nuxt-buefy": "^0.4.4"
},
"devDependencies": {
"fibers": "^5.0.0",
"sass": "^1.34.0",
"sass-loader": "^10.2.0"
}
}
and here is my Express javascript file API:
const express = require("express");
const sms = require("./infoSms/index");
const router = require("../api/routes/routesIndex");
const { db, auth, timestamp } = require("./dataBase/index");
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
port = process.env.PORT || 3000;
app.use(router);
if (require.main === module) {
app.listen(port, () => {
console.log(`server is up ` + port);
});
} else {
console.log("server is up by Nuxtjs");
}
module.exports = app;

The setup is explained pretty well in the official #nuxtjs/axios documentation
export default {
modules: [
'#nuxtjs/axios'
],
axios: {
baseURL: 'http://localhost:4000', // Used as fallback if no runtime config is provided
},
publicRuntimeConfig: {
axios: {
browserBaseURL: process.env.BROWSER_BASE_URL
}
},
privateRuntimeConfig: {
axios: {
baseURL: process.env.BASE_URL
}
},
}
Also, as explained there
The use of runtime config is mandatory in case of using environment variables in production, otherwise, the values will be hard coded during build and won't change.
Usually, webservices are running on port 80 (https) or 443 (https), double-check that this is what you do have in your dashboard (https://dashboard.heroku.com/apps/<your-app>/settings). Even tho you probably don't even need to specify it.
Give a read to the deployment page to see the few steps required so far aka
heroku create myapp
heroku buildpacks:set heroku/nodejs
heroku config:set HOST=0.0.0.0
git push heroku master // git push heroku develop:master if working on develop and not master
Moreover, prefer using this approach for env variables in Nuxt: https://stackoverflow.com/a/67705541/8816585

Related

css files not being copied to dist folder webpack5

I am getting the following error, along with broken css being applied to my webpage.
This at first glance looks like an issue with css, however this file doesn't exist at ALL in the dist folder that gets generated when I run npm run build:development
Refused to apply style from 'http://localhost:3457/dist/main.css' because its MIME type
('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled
these are the run scripts in my package.json
"scripts": {
"start": "cross-env BABEL_ENV=development webpack-dev-server --progress --config conf/webpack.config.development.js",
"build:server": "cross-env BABEL_ENV=development webpack-dev-server --progress --config conf/webpack.config.development.js",
"build:development": "cross-env BABEL_ENV=development webpack --progress --config conf/webpack.config.development.js",
"build:staging": "cross-env BABEL_ENV=production webpack --progress --config conf/webpack.config.staging.js",
"build:production": "cross-env BABEL_ENV=production webpack --progress --config conf/webpack.config.production.js",
"clean": "rimraf dist",
"lint": "eslint . --ext=jsx --ext=js || true",
"lint:styles": "stylelint \"scss/*.scss\" --syntax scss || true"
},
and this is my webpack.config.development.js file that is supposed to configure the webpack, supposedly.
const webpack = require('webpack');
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
// const ExtractTextPlugin = require('extract-text-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const mainPackageJson = require('./../package.json');
// File locations
const PATHS = {
js: path.resolve(__dirname, '../js'),
dist: path.resolve(__dirname, '../dist'),
modules: [
path.resolve(__dirname, '../node_modules/cleave.js')
]
};
exports = module.exports = {
mode: 'development',
stats: {
errorDetails: true
},
entry: [
'babel-polyfill',
'webpack-dev-server/client?http://localhost:3457',
'webpack/hot/only-dev-server',
'./js/index'
],
output: {
path: PATHS.dist,
filename: '[name].js',
publicPath: '/dist'
},
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {name: 'vendor', filename: 'vendor.js'}
}
}
},
resolve: {
extensions: ['.js', '.jsx']
},
devtool: 'eval-source-map',
module: {
noParse: /node_modules\/quill\/dist\/quill.js/,
rules: [
{
test: /\.gif$/,
type: 'asset/inline'
// loader: 'url-loader',
// query: {
// mimetype: 'image/png'
// }
},
{
test: /\.woff(2)?(\?v=[0-9].[0-9].[0-9])?$/,
type: 'asset/inline'
// loader: 'url-loader',
// query: {
// mimetype: 'application/font-woff'
// }
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9].[0-9].[0-9])?$/,
type: 'asset/resource'
// loader: 'file-loader',
// query: {
// name: '[name].[ext]'
// }
},
{
test: /\.(sa|sc|c)ss$/i,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: PATHS.dist
}
},
"css-loader",
"postcss-loader",
"sass-loader",
],
},
{
test: /\.jsx?$/,
rules: [{loader: 'react-hot-loader/webpack'}, {loader: 'babel-loader'}],
include: [
PATHS.js,
...PATHS.modules
]
}
]
},
plugins: [
// new webpack.optimize.CommonsChunkPlugin({name: 'vendor', filename: 'vendor.js'}),
require('autoprefixer'),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
// new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
__CONTENT__: JSON.stringify('#content'),
__DEV__: true,
__NOOP__: function () {
},
__VERSION__: JSON.stringify(mainPackageJson.version)
}),
new CopyPlugin(
{
patterns: [{
from: path.resolve(__dirname, '..', 'conf.js'),
to: 'conf.js'
}]
}
),
],
devServer: {
static: path.resolve(__dirname, '..'),
historyApiFallback: true,
hot: true,
host: 'localhost',
port: 3457
}
};
Perhaps I am misunderstanding something.
I am attempting to update the application from webpack3 to webpack5, among other outdated dependencies.
What is wrong?, why isn't a main.css file being generated or copied into the dist folder for it to be accessed?
When I had (which I deleted) files from an older dist folder built, it appeared to work correctly.

Not getting a drop down menu for "img" in Gatsby / GraphQL

I am following this tutorial.
I have trips.json in my data folder
[
{
"img": "../assests/images/bahamas.jpg",
"name": "Bahama Beach"
},
{
"img": "../assests/images/china.jpg",
"name": "Chinese Palace"
},
{
"img": "../assests/images/dubai.jpg",
"name": "dubai"
},
{
"img": "../assests/images/monke.jpg",
"name": "monke",
"alt": "monke monke monke monke"
}
]
Here is my gatsby-config.js
module.exports = {
siteMetadata: {
title: `My Gatsby Project`,
description: `Made with Gatsby.`,
author: `#gatsbyjs`,
siteUrl: `https://gatsbystarterdefaultsource.gatsbyjs.io/`,
},
plugins: [
`gatsby-transformer-json`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `./src/data`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/assets/images`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `videos`,
path: `${__dirname}/src/assets/videos`,
},
},
{
resolve: `gatsby-plugin-styled-components`,
options: {
// Add any options here
author: `me`,
},
},
`gatsby-plugin-react-helmet`,
`gatsby-plugin-image`,
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
},
},
`gatsby-plugin-gatsby-cloud`,
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
],
}
At localhost:8000/__graphql, I am getting a checkbox for "img."
However, the tutorial makes extensive use of many properties within the "img" attribute.
I have tried to stop the process, do gatsby clean and restart the process.
So I want to figure out why I am not seeing this and how I can get this drop-down to appear on my screen.
Solved it by adding the following to gatsby-node.js
exports.createResolvers = ({
actions,
cache,
createNodeId,
createResolvers,
store,
reporter,
}) => {
const { createNode } = actions
createResolvers({
StrapiPageContentArticleGallery: {
imageFile: {
type: `File`,
resolve(source, args, context, info) {
return createRemoteFileNode({
url: `${source.url}`, // for S3 upload. For local: `http://localhost:1337${source.url}`,
store,
cache,
createNode,
createNodeId,
reporter,
})
},
},
},
})
}

Nuxt.js vuetify.css not found

I'm getting a compilation error when trying to run nuxt with vuetify. It says that vuetify.css was not found with the dependency absolute path. I checked in buildDir/App.js and vuetify.css is the only dependency to reference a fullpath. Is there a reason to that ?
What do I miss ?
yarn dev
This dependency was not found: friendly-errors 10:34:11
friendly-errors 10:34:11
* .\full\path\to\myproject\src\node_modules\vuetify\dist\vuetify.css in ./myproject/prod/server/nuxt/App.js
friendly-errors 10:34:11
To install it, you can run: npm install --save .\full\path\to\myproject\src\node_modules\vuetify\dist\vuetify.css
buildDir/App.js
...
import '..\\..\\..\\src\\assets\\main.css'
import '..\\..\\..\\src\\assets\\variables.scss'
import '.\\full\\path\\to\\myproject\\src\\node_modules\\vuetify\\dist\\vuetify.css'
import _6f6c098b from '..\\..\\..\\src\\layouts\\default.vue'
...
package.json
"dependencies": {
"#nuxtjs/axios": "^5.9.2",
"#nuxtjs/firebase": "^4.1.0",
"firebase": "^7.10.0",
"lodash": "^4.17.15",
"nuxt": "^2.0.0",
"nuxt-i18n": "^6.5.0"
},
"devDependencies": {
"#babel/runtime-corejs3": "^7.8.7",
"#nuxtjs/dotenv": "^1.4.1",
"#nuxtjs/vuetify": "^1.11.0",
"#vue/test-utils": "^1.0.0-beta.27",
"babel-jest": "^24.1.0",
"core-js": "3",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-prettier": "^3.0.1",
"jest": "^24.9.0",
"prettier": "^1.16.4",
"vue-jest": "^4.0.0-0"
}
nuxt.config.js
import webpack from 'webpack'
require('dotenv').config({ path: '../.env' })
export default {
mode: 'universal',
server: {
host: process.env.HOST_NAME,
port: process.env.HOST_PORT
},
env: process.env,
head: {
titleTemplate: '%s - ' + process.env.npm_package_name,
title: process.env.npm_package_name || '',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900' },
]
},
loading: { color: '#fff' },
css: [
'#/assets/main.css',
'#/assets/variables.scss'
],
plugins: [],
buildModules: [
['#nuxtjs/vuetify', { }],
['#nuxtjs/dotenv', { path: '../', filename: '.env' }]
],
modules: [],
vuetify: {
customVariables: ['~/assets/variables.scss'],
optionsPath: "./vuetify.options.js",
},
buildDir: "../prod/server/nuxt",
build: {
plugins: [
new webpack.ProvidePlugin({
'_': 'lodash'
})
],
extractCSS: true,
extend (config, ctx) {},
babel: {
presets({ isServer }) {
return [
[
require.resolve('#nuxt/babel-preset-app'),
{
buildTarget: isServer ? 'server' : 'client',
corejs: { version: 3 }
}
]
]
}
}
}
}

grunt connect proxy + grunt-livereload 404 when reload

I'm have problem with my Gruntfile config but I don't know how resolve this. When my path has single route ex: localhost:9000/contractor reload work fine, but when reload localhost:9000/add/something I get error 404 beacuse browser search files in 'add' directory not in main directory example: GET localhost:9000/add/bower_components/bootstrap/dist/css/bootstrap.css
Directory 'add' not exist. I'm using Angular 1.6.0 and angular-route 1.6.0
Gruntfile.js
'use strict';
var modRewrite = require('connect-modrewrite');
var config = {app: 'app'};
var mountFolder;
module.exports = function (grunt)
{
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-jshint');
require('load-grunt-tasks')(grunt);
mountFolder = function (connect, dir)
{
return connect['static'](require('path').resolve(dir));
};
grunt.initConfig({
config: config,
watch: {
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: ['<%= config.app %>/index.html',
'<%= config.app %>/*.js',
'<%= config.app %>/modules/**/*']
}
},
connect: {
options: {
port: 9000,
livereload: 35729,
hostname: 'localhost'
},
livereload: {
options: {
open: true,
middleware: function (connect)
{
return [
// in case of using html5Mode - makes accessible uris without hashbang but containing view's path
modRewrite(['!\\.html|\\.js|\\.svg|\\.css|\\.png|\\.jpg|\\.ttf|\\.woff|(\\api.+)$ /index.html [L]']),
mountFolder(connect, config.app),
connect().use('/bower_components', connect.static('./bower_components')),
require('grunt-connect-proxy/lib/utils').proxyRequest];
}
}
},
proxies: [{
context: '/api',
host: 'localhost',
port: 3000,
changeOrigin: true
}],
jshint: {
default: {
options: {
jshintrc: true
},
files: {
src: ['app/**/*.js', 'test/**/*.js', '!app/bower_components/**/*.js']
}
},
verify: {
options: {
jshintrc: true,
reporter: 'checkstyle',
reporterOutput: 'target/jshint.xml'
},
files: {src: ['app/**/*.js', 'test/**/*.js', '!app/bower_components/**/*.js']}
}
}
}
}
);
grunt.registerTask('serve', ['configureProxies', 'connect:livereload', 'watch']);
grunt.registerTask('default', ['serve']);
};
My dependecy:
"devDependencies": {
"connect-livereload": "0.5.2",
"connect-modrewrite": "0.9.0",
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-connect": "0.7.1",
"grunt-contrib-jshint": "0.11.3",
"grunt-contrib-watch": "0.6.1",
"grunt-connect-proxy": "0.2",
"load-grunt-tasks": "3.0.0"
}
Problem was be on angular-route 1.6.0 . I'm add
<base href="/" />
to index.html before linked css style and work.

Webpack Config did not export an object

WEBPACK # 2.2
WEBPACK-MERGE # 2.4
I am using webpack merge to do a smart dev or production config.
My start script looks like
}
"scripts": {
"start": "webpack --env=production & node start.js",
"dev": "webpack-dev-server --env=dev",
},
and my webpack-config looks like this:
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const webpackMerge = require('webpack-merge')
const baseConfig = function(env) {
return {
output: {
path: '/public/',
filename: 'index.js',
publicPath: '/public/',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: "style-loader",
loader: "css-loader",
publicPath: "/public/",
}),
},
],
},
resolve: {
extensions: ['.js', '.css'],
},
plugins: [
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify(env) },
}),
new ExtractTextPlugin({
filename: "bundle.css",
disable: false,
allChunks: true,
}),
],
}
}
module.exports = function(env) {
return webpackMerge(baseConfig(env), env === 'dev' ? {
devtool: 'cheap-module-source-map',
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./app/index.js',
],
devServer: {
hot: true,
publicPath: '/public/',
proxy: {
"/api/**": "http://localhost:3333",
"/auth/**": "http://localhost:3333",
},
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
],
} : {
devtool: 'inline-source-map',
entry: [
'./app/index.js',
],
plugins: [
new webpack.optimize.UglifyJsPlugin({
comments: false,
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
}),
new webpack.optimize.AggressiveMergingPlugin(),
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
],
})
}
Webpack successfully compiles locally but when I attempt to deploy it to heroku, the output in papertrail is as seen below:
> webpack --env=production & node start.js
Config did not export an object.
Any ideas?
I had the same issue, I forgot to install webpack dev server:
npm install --save-dev webpack-dev-server
Hope it helps!

Resources