I am using ember-cli-mirage to serve for requests. As I have my rails api to serve those request, how i shd remove or uninstall ember-cli-mirage from my ember ?
If am removing mirage folder, am getting build error !!
You should leave Mirage installed (and the folder on disk) but disable the server whenever you want to use your actual backend API. This will let you use Mirage in selective environments, for example in testing.
By default, Mirage is disabled in production, and also in development when using the -proxy option.
To disable Mirage explicitly, you can set the enabled config option to false. For example, to always disable in development:
// config/environment.js
...
if (environment === 'development') {
ENV['ember-cli-mirage'] = {
enabled: false
};
}
Leave mirage installed, if you want to use your backend api just launch ember with
ember s --proxy http://localhost:8000
if api's are running on your machine on port 8000.
More info on mirage official site: http://www.ember-cli-mirage.com/docs/v0.3.x/configuration/#enabled
Related
I have this rails application which handles the backend for the app and I also have a Vue project in the root of the same directory acting as a front end. Now, the rails server runs on port:3000 and Vue runs on Port:8081 by default.
I need to make sure both communicate through a single port.
If you are using webpack or the Vue CLI you can easily define a reverse proxy in the configuration of your front-end project. Here is an example of such a webpack config:
devServer: {
proxy: {
'/api': 'http://localhost:3000'
}
}
When defining such a configuration, your front-end devserver will redirect each request from http://localhost:8081/api/* to http://localhost:3000/api/*. You can also define another pattern than /api depending on your needs.
In Vue CLI, you can use the same configuration and add it to the vue.config.js file. Make sure to add the webpackConfig into the section configureWebpack:
module.exports = {
configureWebpack: {
[...the config like above...]
}
};
Here are some documentation references:
Webpack Dev Server: Proxy
Vue CLI Webpack Config
The above described configuration works for the development environment. The productive environment must be handled differently, because there is no webpack devserver in production. You need to build the static HTML/JS/CSS content with webpack and then either put the generated code into the Rails application and serve it from there statically or you use two web servers (one for Rails and one for serving the static files) and put a reverse proxy in front of them.
We're running an EmberCLI application in our infrastructure, and I'm tasked to make it work better with the rest of our services. One thing that's a bit interesting about EmberCLI is that all it's configuration variables are baked into the build by default. (Specifically in the <meta> tag).
I had trouble finding a way to supply runtime configuration. We have an "API_URL" environment variable that's supplied to all our services so they can find the API. What is the recommended way to supply this url to EmberCLI at run-time, so I can avoid a rebuild and have fully-built docker containers with our frontend application.
If you want to use an environment variable for configuration ember-cli-dotenv will help. It allows you to access an environment variable in config/enviroment.js:
// config/environment.js
module.exports = function(environment){
return {
apiUrl: process.env.API_URL
}
};
You have to whitelist the environment variables used in ember-cli-build.js:
// ember-cli-build.js
module.exports = function(defaults) {
var app = new EmberApp(defaults, {
dotEnv: {
clientAllowedKeys: ['API_URL']
}
});
return app.toTree();
};
A short side note: Configuration variables are baked into the build by ember-cli cause ember-cli has done it's job after build. Files generated should be served by a normal webserver like nginx. The webserver which could be started with ember serve should not be used in production.
I have an ember-cli application that I'm deploying to Divshot using the ember-cli-divshot addon. In my config/environment.js file I want to have a different api between development and production.
Inside var ENV = {} I have:
api: 'http://localhost:3000'
And the I have this for production:
if (environment === 'production')
ENV.api = '<my production api>'
}
However when I do divshot push production, my Ember app is trying to hit the localhost endpoint for the api.
After some work I realized that I need to make sure the I'm building and deploying the production version of my Ember app, which is actually built into the ember-cli-divshot addon by prepending the deploy command with ember like this:
ember divshot push production
After installing Elixir 0.14.1 and the Phoenix web framework then launching the web server I am unable to preview the web site. Does anyone know how to get this working?
Nitrous currently does not have explicit support for Elixir boxes so you have to create a box using any of the supported services (i.e. Ruby on Rails). Then you can use Autoparts:Uninstall to remove the unneeded parts and Autoparts:Install to add Elixir (currently there is an Elixir 0.14.1 part which shows up if you search).
Once Elixir is installed, open up a Nitrous console and install the latest Phoenix framework by cloning from github as documented by the README.md on the phoenixframework github site.
Create a Phoenix application in the console from the phoenix root directory, as described in the README.md. In the discussion below we assume the phoenix app is named ws.
The Nitrous IDE preview feature requires that the webserver runs on 0.0.0.0 using port 3000 (other ports are also supported) with ssl turned off. To do this, modify /lib/ws/config/prod.ex to look like:
defmodule Ws.Config.Prod do
use Ws.Config
config :router, port: 4000,
host: "0.0.0.0",
ip: {0, 0, 0, 0},
ssl: false,
# Full error reports are disabled
consider_all_requests_local: false
config :plugs, code_reload: false
config :logger, level: :error
end
Note that we're modifying the production configuration. You may decide do use the dev.ex or config.ex configuration as well/instead. To start the server from within the Nitrous console, make sure you are in the application's root directory then enter:
MIX_ENV=prod mix phoenix.start
to start the server. You should now be able to preview the resulting site from within the Nitrous IDE using the Preview:Port 3000.
I have an action, that generates a PDF files and save it in the /public/output.pdf.
When I set
config.serve_static_assets = false
this file can't be found.
What's wrong ?
From the documentation:
"config.serve_static_assets configures Rails itself to serve static
assets. Defaults to true, but in the production environment is turned
off as the server software (e.g. Nginx or Apache) used to run the
application should serve static assets instead. Unlike the default
setting set this to true when running (absolutely not recommended!) or
testing your app in production mode using WEBrick. Otherwise you won´t
be able use page caching and requests for files that exist regularly
under the public directory will anyway hit your Rails app."
Which means that if you set that to false Rails will not serve any assets from your public folder as it is assumed that a front-end web server (apache/nginx) will handle it. This lessons the load on Rails as the front-end server is much, much more efficient at serving files directly.
After testing, I came to this conclusion:
1) when using the command
rails s -e production
Rails will only serve the statics files. Any other file created after you compile your assets will not be found.
To handle this, you need to execute your application under a web server like Apache, Nginx or other. These web servers will serve this files for you.
This looks to be obvious, but not for a beginner.