If my Meteor app is live on www.example.com, I can access the subdomain with location.hostname:
Template.name.helpers({
subdomain: () => location.hostname.split('.').shift(),
});
So that this page:
<p>You are on {{subdomain}}</p>
Will say "You are on www".
Then I can build a test app with this command:
$ meteor run ios --mobile-server=www.localhost:3000
And in this app, the subdomain helper simply returns localhost. I assume that is the same if I run this:
$ meteor build --server www.example.com
How do I find www (or whatever the subdomain is that I passed in the server flag) from my front end meteor code?
Related
I never deployed any project before and I'm currently running with an issue while deploying a next.js app to godaddy. I uploaded my next.js app to the public_html folder of my cpanel and then i connected through ssh and executed the npm run dev command with server.js pointing to my domain name as hostname and 3000 as port number however, to access it i will have to write in the url www.mydomain.com:3000 . I learned that in order to access it by the following url www.mydomain.com I have to specify port 80 in the server.js file. However, when I do so and run the npm run dev command it says that I do not have the permission to port 0:0:0:0:80
Screenshot here
I have a VPS server and a domain name. I am doing something wrong or is there something I missed? Should I not use my domain name as hostname in the server.js file? Should I maybe keep the hostname as my VPS ip and port 3000 then point my domain to read from this address? I am a beginner with no previous exprience in deployement and this is my first next.js app ever.
Any help is appreciated and thank you!
I was developping a app with React app. In developing env i was using proxy but I'm deploying the app and I saw that proxy didn't work in.
I read about http-proxy-middleware. It can be a solution or it don't works too?
Any way to do this without config the server with redirects to other port?
I need to continue fetching to my API server.
The best way what I found without configure server and NGINX is follow this steps:
Build front
Move folder into a backend server.
Put that code after routes:
if (process.env.NODE_ENV === 'production') {
app.use(express.static(`${__dirname}/yourFrontFolder/build`));
app.get('*', (req, res) => {
res.sendFile(`${__dirname}/yourFrontFolder/build/index.html`);
})
...
And build your backend code and access to your backend port like frontend.
You don't usually need a proxy in your React app when it is deployed. To deploy, you usually run npm run build, which creates a build directory containing all the compiled JavaScript and HTML files you need for the deployment. These are then served by a web server, such as NGINX or by your backend application.
I have developed node rest api and vuejs web applications,
Im trying to deploy both project in to one aws server which run ubuntu.
Both applications have different port,
domain I try to configure api.example.com for api and example.com for vue app.
I can run both applications once after running the command in SSH, but I need them to run it forever.
What I did,
Deploy to apps separately
Apps can access with ports
I need them access
api.example.com
example.com
what are the step to do,
Any changes host file.
I found another way to deploy vue app and express/nodejs in one server without using PM. This what I did
Build your vue code using npm run build command. This will create a folder dist which should have index.html file and static folder.
Copy dist folder into your server code repository. In my case I created a folder public and moved the dist folder inside public.
In app.js file right before module.exports=app line, copy the following lines of code
//These 2 lines make sure that vue and express app are coming from the same server.
app.use('/static', express.static(path.join(__dirname,"../public/dist/static/")));
app.get('/', function(req,res) {
res.sendFile('index.html', { root: path.join(__dirname, '../public/dist/') });
});
First line make sure that the /static folder is accessible and second line will serve the index.html file when you run the node server. Routing between components will be taken care by vue.
This is how we are running our VueJS UI and ExpressJS REST API from the same server.
We are managing our services with PM2.
VueJS (Dev Environment, You can add the same settings to production)
In package.json add "start": "HOST='0.0.0.0' PORT=80 npm run dev",, where 80 is the port VueJS is listening on, to the "scripts": {..} array. Then, after installing PM2, (for dev) we can start VueJS with cd /location/of/vue/root; sudo pm2 start npm run dev --name Vue -- start. (Make sure that Apache is not running).
Please note that setting the HOST to 0.0.0.0 is important. Do not set it to LocalHost or your Servers IP address or you may run into issues.
ExpressJS
In the /location/of/express/app.js add this similar to the bottom of the file:
app.listen(process.env.PORT || 8081), where 8081 is the port your REST API should be listening on. I can then start it with sudo pm2 start /location/of/express/app.js --name Express
At this point, the VueJS should be available at www.example.com (implied Port 80) and the REST API would be available at www.example.com:8081.
If you want to have api.example.com/ point to the API, you need to make sure that your DNS is pointing the "api" subdomain to the desired port, or you may have to add the port into the URL as above.
Additionally, you can easily follow the logs through PM2 as well with pm2 logs APPNAME --lines 100.
I want to write a simple CMS using Node.js (with Express) and Ember.js. I am totally new to Ember.js, but I am familiar with Angular. I see Ember.js is very close to Angular because it uses a CLI with "ember serve" command to run the client app. But in Node.js I also have to start the server using "npm start". As any CMS, there is a "public" part (the site pages) served by Express using Handlebars and an "admin" part (the reserved area, with administrative pages) that is the web app wrote in Ember.js. Is there a way to have both client and server routes from a single base domain and port (i.e. http://localhost:3000/ for public pages and http://localhost:3000/admin/ for the admin pages)? And there is a way to start the whole project with a single command, instead of typing "npm start" for the server and "ember serve" for the client? Maybe the only way is to render Ember.js templates server-side with Fastboot? I am very confused about the development of a web app like this.
ember serve is starting a development server. You should not run this in production. Just build the application using ember build --prod and serve it as you want.
To forward requests to your api in development, use proxy option of ember serve. E.g. ember serve --proxy http://127.0.0.1:3000. This will startup ember development server (providing live reload at file changes) at port 4200 and forward api requests to port 3000 on 127.0.0.1.
If this is not enough for you (talking about development environment only), you could always run a nginx proxy providing that magic...
Do not forget to adjust rootURL configuration of your ember app, if not serving from webroot.
I recently deployed a meteor app using the following command:
$ meteor deploy example.com
and later (thinking that it was the same) using the following:
$ meteor deploy www.example.com
It end up serving two different versions of the app, one hosted in example.com and other hosted in www.example.com.
Can I revert one of the deploys? Which one should I revert?
If not, what kind of configs should I set on my domain provider?
When people go to your page, do you want them to see mydomain.example or www.mydomain.example?
If it's mydomain.example, then you want to set your DNS zone file with an A record for the domain that points to the IP of origin.meteor.com
If it's www.mydomain.example, then you want to set your DNS zone file with a CNAME for the subdomain "www" that points to origin.meteor.com
Then, you want to set "domain forwarding" from one of those choices to the other. For example, I've set up http://playlistparty.net to forward to http://www.playlistparty.net.
After this, you just run:
meteor deploy www.playlistparty.net
You can delete the deployment you won't be using with the --delete option.
meteor deploy www.playlistparty.net --delete
Deploying on a custom domain name
Deploy meteor to your domain name:
meteor deploy mydomain.com
Set your CNAME record for *.mydomain.com or www.mydomain.com (if you only want to set the www subdomain) and mydomain.com to : origin.meteor.com
OR
point your 'A' record for *.mydomain.com and mydomain.com to : 107.22.210.133.
To remove an exising one you might have typed by accident:
meteor deploy www.mydomain.com --delete
If you want www to redirect to non-www you can use this method. You can also modify the code a little to do it other way around.
Simply set
# (CNAME) : origin.meteor.comm
www (CNAME) : origin.meteor.com
Then, deploy your main app (without www).
meteor deploy yourapp.example
Now, create a new meteor app called redirect with
meteor create redirect
cd redirect
Set the generated js file contents like this:
if (Meteor.isClient) {
var url = document.URL;
url = url.replace("www.", "");
window.location.href = url;
}
Then deploy your redirect app (with www)
meteor deploy www.yourapp.example
What you did is, you deployed two different applications to www and non-www of your domain. All the meteor app at www does is to redirect you to non-www domain. It will also redirect www.yourapp.example/some/path to yourapp.example/some/path.
I did a lot of googling on this, so I'll share what ended up working for me. I was looking for all queries to go to the HTTPS and www version of my site. Just setting up the CNAME did not actually change to redirect to the www version. I'm hosting on Modulus and ended up doing the following:
Force HTTPS
Modulus has an HTTPS redirect, else I've used the Force-SSL package and NGINX to do this successfully in previous apps not hosted on Modulus.
Point domain at hosting IP
Set up you domain, example.com, A-record to point at our hosting IP.
Set up my CNAME for 'www' subdomain to point to the same IP.
Force www
Set the environment variable ROOT_URL to 'https://www.example.com'
Download the canonical package: https://atmospherejs.com/wizonesolutions/canonical