In The Force Awakens, there is a very powerful weapon harnessed by the First Order that can destroy planets. At a critical moment in the movie, the Resistance learns that their planet is the next target. In the film, we see Leia receive a message of some kind, which appears to inform her. But how was this information acquired? How could they know?
In the WGA leaked script, the datacard that Leia gets which says that the weapon is being recharged ALSO tells her it's being targeted at D'Qar
(eyes on datacard)
The First Order: they're charging
the weapon again, now.
(then, heart sinking)
Our system is the next target.
Leia decided to attack without even knowing the next target anyway
After that, she deduced they were next target because it was a slam dank obvious next move for First Order
They knew they were an immediate urgent next target because the weapon was being immediately recharged.
Leia originally, even earlier, decides they need to attack without knowing what the target is.
All quotes from Alan Dean Foster's official TFA novelization, which is fully Disney canon.
“We have to wait until the technical staff have run their detailed analysis,” Wexley said. “Then, once they’ve done that—”
Leia cut him off. Han grinned, but not so she could see it. She was good at cutting people off, he knew.
“We don’t have time to wait on analyses and scientific hypotheses. Han’s right. We have to act, and act now.” He eyed her in surprise—and concealed that reaction, too.
“This is the moment that counts,” she continued. “Everything we’ve ever fought for is at stake. We can’t wait on theories. We need something, anything, so we can fight back!” She straightened. “We have to take this weapon down before it can be used again.”
In case you're wondering what her motivation to rush was? Well, aside from generic "she'a good person who doesn't like the idea of billions of people dying", we know exactly what her PTSD is about: She witnessed Alderaan being destroyed 30+ years earlier.
“Admiral,” she said, “we must find this new weapon’s point of origin. As soon as possible and before it can be used again.”
Statura nodded tersely. “I’ll send a reconnaissance ship immediately.”
She acknowledged his response as Captain Wexley called to her. “General, we’re ready for you.”
It was to be a conference on strategy like no other, she knew. To confront a threat that exceeded everything else that had gone before it. She spared a moment’s thought for her envoy, Sella, who had been on the Republic capital world when it had been destroyed. And another moment for all who had perished, regardless of their personal or political beliefs. First Alderaan, now the Hosnian system. No one, she knew, should have to be witness to the death of an entire world.
Having said that, it doesn't really take more than 2 working brain cells to figure out that if First Order's first target was the center of New Republic, their second target would be Rebellion's main base. That's not in canon... but come on, the fact that they all have more than 2 brain cells IS in canon.
And, lo and behold, Leia does get just that lightbulb moment right after already having decided to attack:
“The situation could not be worse,” C-3PO murmured.
Raising a hand for attention, Leia held up the readout. “According to this, we don’t have time to study the situation even if we decided to do so. Our team has detected an enormous quantity of dark energy surging toward the world Finn has identified for us. That can only mean one thing.” She paused for emphasis. “They’re loading the weapon again. I think we can all take a good guess as to what their next target will be.”
C-3PO lowered his golden head. “I was wrong. It can be worse.”
As we witness in the scene at Maz Canata's hideaway (where the First Order and the Rebellion are simultaneously alerted to the presence of BB8 at their location), both forces have a significant network of spies and sympathisers. Whilst Fin (being a lowly sanitation worker) bringing them valuable information would suggest that the rebellion don't have anyone inside the First Order passing them intel, it's plausible they have someone close enough to determine that the New Weapon's firing vector was aligned with the direction of the rebel base, and make a reasonable assumption.
Remember, the Weapon is already 'aimed' at the planet when it begins charging from the Sun, so it's giving away it's direction of fire the entire time it's warming up. Enough time for the Rebels to launch a counter assault and attack fleet, so it must take some considerable time.